【问题标题】:AmazonClientException: Unable To Load Credentials from any Provider in the ChainAmazonClientException:无法从链中的任何提供商加载凭证
【发布时间】:2017-10-27 18:57:16
【问题描述】:

我的 mule 应用程序将 json 记录写入运动流。我使用 KPL 生产者库。在本地运行时,它会从 .aws/credentials 中选择 AWS 凭证并将记录成功写入 kinesis。

但是,当我将应用程序部署到 Cloudhub 时,它会引发 AmazonClientException,这显然是由于无法访问 DefaultAWSCredentialsProviderChain 类支持的任何目录。 (http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html)

这是我附加凭据的方式,它在 .aws/credentials 中本地显示:

config.setCredentialsProvider( new 
DefaultAWSCredentialsProviderChain());

我找不到使用 my-app.properies 文件显式提供凭据的方法。

然后我尝试使用 getter/setter 创建一个单独的配置文件。将访问密钥和私钥设置为私有,然后执行 getter:

public AWSCredentialsProvider getCredentials() { 
    if(accessKey == null || secretKey == null) { 
        return new DefaultAWSCredentialsProviderChain(); 
    } 

    return new StaticCredentialsProvider(new BasicAWSCredentials(getAccessKey(), getSecretKey())); 
} 

}

这是打算用这种方式代替 DefaultAWSCredentialsProviderChain 类---

config.setCredentialsProvider(new AWSConfig().getCredentials());

部署时仍然抛出相同的错误。 以下 repo 声明可以提供显式凭据。我需要帮助来弄清楚如何,因为我找不到合适的文档/示例。 https://github.com/awslabs/amazon-kinesis-producer/blob/master/java/amazon-kinesis-producer-sample/src/com/amazonaws/services/kinesis/producer/sample/SampleProducer.java

【问题讨论】:

  • 你查看PropertiesFileCredentialsProvider了吗?
  • 我没有。现在尝试。这是我试图做到这一点的方法,如果我走错了方向,请纠正我。 PropertiesFileCredentialsProvider localProperties = new PropertiesFileCredentialsProvider(credPath); localProperties.getCredentials(); config.setCredentialsProvider(localProperties);

标签: java mule amazon-kinesis anypoint-studio cloudhub


【解决方案1】:

我也遇到了同样的问题,我得到了这个解决方案,希望这也对你有用。

@Value("${s3_accessKey}")
private String s3_accessKey;

@Value("${s3_secretKey}")
private String s3_secretKey;

//this above  value I am taking from Application.properties file

BasicAWSCredentials creds = new BasicAWSCredentials(s3_accessKey, 
s3_secretKey); 

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(creds))
    .withRegion(Regions.US_EAST_2)
    .build();

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2019-06-20
    • 1970-01-01
    • 2021-08-08
    • 2017-07-10
    相关资源
    最近更新 更多