【发布时间】:2015-08-14 19:23:41
【问题描述】:
我有一个小型 Spring Boot 应用程序,使用 Spring Cloud AWS (1.0.0.RELEASE) 访问 SQS 队列。它正在部署在具有实例配置文件集的 EC2 实例上。看来 AWS 方面正在发挥作用,因为我可以访问两个相关的元数据链接:iam/info 和 iam/security-credentials/role-name,它们确实包含正确的信息。可以肯定的是,我使用了 aws cmdline 实用程序(aws sqs list-queues)并且它确实有效,所以我猜设置没问题。但是,当应用程序启动时,它会读取 application.properties(其中包含行 cloud.aws.credentials.instanceProfile=true)然后丢弃以下警告:com.amazonaws.util.EC2MetadataUtils: Unable to retrieve the requested metadata,最后抛出以下异常:
Caused by: com.amazonaws.AmazonServiceException: The security token included in the request is invalid. (Service: AmazonSQS; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1071)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:719)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:454)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:294)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2291)
at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:516)
at com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient.getQueueUrl(AmazonSQSBufferedAsyncClient.java:278)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:78)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:37)
at org.springframework.messaging.core.CachingDestinationResolverProxy.resolveDestination(CachingDestinationResolverProxy.java:88)
at org.springframework.cloud.aws.messaging.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:295)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.start(SimpleMessageListenerContainer.java:38)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
... 17 common frames omitted
...这意味着由于某种原因 Spring Cloud AWS 没有使用 Instance Profile 凭证。我在com.amazonaws.request 上启用了debug 日志级别,似乎发送的请求没有访问密钥和密钥。
DEBUG --- com.amazonaws.request : Sending Request: POST https://sqs.eu-west-1.amazonaws.com / Parameters: (Action: GetQueueUrl, Version: 2012-11-05, QueueName: xxxxxxxxxxxxx, ) Headers: (User-Agent: aws-sdk-java/1.9.3 Linux/3.14.35-28.38.amzn1.x86_64 Java_HotSpot(TM)_64-Bit_Server_VM/25.45-b02/1.8.0_45 AmazonSQSBufferedAsyncClient/1.9.3, )
有人知道我遗漏了什么,或者至少有任何提示如何进一步调试吗?
编辑:在浏览了一下 spring-cloud-aws 代码之后,我有点前进了。与 jar 捆绑在一起的配置文件 application.properties 具有 accessKey 和 secretKey 的一些文本值。我自定义的application.properties 没有这些属性,这可能导致spring 使用捆绑文件中的值作为默认值。我已经将它们包含在空值中,这将异常更改为com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain。 AWS SDK 似乎配置了 DefaultProviderChain,但它仍然无法获取实例配置文件凭据。
【问题讨论】:
标签: java amazon-web-services spring-boot spring-cloud