Vin*_*ntS 5 spring amazon-sns spring-boot
我尝试在 Spring Boot 应用程序中使用 AmazonSNS,并且可以在本地使用它,但是当我将其部署到开发服务器上时,我收到此错误:
Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]
Run Code Online (Sandbox Code Playgroud)
如果我没有弄错的话,我的服务器将无法获取任何 AWS 凭证。我不明白为什么,因为 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 设置为环境变量。我的代码看起来像这样:
private AmazonSNS amazonSNS;
@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();
Run Code Online (Sandbox Code Playgroud)
和这个:
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();
Run Code Online (Sandbox Code Playgroud)
但我总是遇到同样的错误。
晚了两年——但我想我已经明白了。
正如 @vincentS 指出的 - 这与这种依赖性有关。但你不需要删除它。
设置属性
cloud.aws.credentials.useDefaultAwsCredentialsChain = true
在您的应用程序(Yaml 或属性)中,您就可以开始了。(这对我有用)。
来源: https: //cloud.spring.io/spring-cloud-aws/reference/html/
| 归档时间: |
|
| 查看次数: |
11129 次 |
| 最近记录: |