aws-samples / aws-samples/aws-java-sample

Unable to load AWS credentials from any provider in the chain

未關閉
#15 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Java
星號
241
分支
345
PR 合併指標
30 天內沒有已合併 PR

描述

I have my application running on EC2. Trying to access dynamoDB from my Java application. But for every operation, I get "Unable to load AWS credentials from any provider in the chain".

* I have added dynamoDB permissions in the IAM role that gets attached to EC2 instance
* And also configured EC2 to assume that role in trust relationship.

Code:
```try {
AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
AWSCredentials credentials = provider.getCredentials();
if(credentials != null) {
LOG.info("Credentials Key: " + credentials.getAWSAccessKeyId());
LOG.info("Credentials secret: " + credentials.getAWSSecretKey());
}
} catch (Exception e) {
LOG.info("Exception in credentials cause:" + e.getCause() +";message: " + e.getMessage() +";stack: " +e.getStackTrace());
}
```
The getCredentials() line itself throws an Exception with message: "Unable to load AWS credentials from any provider in the chain".
If I do not try to get credentials here and pass it to the DynamoDB client:
```dynamoDBClient = builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, region.getName()))
.withClientConfiguration(clientConfig)
.build();```

Then it throws the same exception when I try to do any operation.

I tried setting up the proxy too:

```ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setProxyHost("yyy");
clientConfig.setProxyPort(port);
clientConfig.setNonProxyHosts("xxx");
clientConfig.setProtocol(Protocol.HTTP);```

and then passing it while creating the client:

``` dynamoDBClient = builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(url, region.getName()))
.withCredentials(credentialProvider())
.withClientConfiguration(clientConfig)
.build();
```
But no success.

Can someone @here guide me what am I missing here?

貢獻指南

開啟貢獻指南

研究方向

Start with the Java snippets using DefaultAWSCredentialsProviderChain.getCredentials(), the DynamoDB builder, and ClientConfiguration proxy settings. Reproduce the credential-chain failure on EC2 and determine whether the missing behavior is in instance-role access, proxy configuration, or client setup; done means documenting a confirmed cause and a reproducible resolution.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
aws, java
領域
authentication, cloud
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。