Spring Cloud AWS SQS 访问被拒绝

标签 spring cloud messaging amazon-sqs access-denied

我目前在尝试使用 Spring Cloud 和 Spring Boot 连接到 AWS SQS 队列时遇到连接问题。我相信我的一切配置都很好,但我得到了:

2015-07-01 18:12:11,926 [WARN][-] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext[487] - Exception encountered during context initialization - cancelling refresh attempt org.springframework.context.ApplicationContextException: Failed to start bean 'simpleMessageListenerContainer'; nested exception is com.amazonaws.AmazonServiceException: Access to the resource https://sqs.us-west-2.amazonaws.com/{Number}/{Queue Name} is denied. (Service: AmazonSQS; Status Code: 403; Error Code: AccessDenied; Request ID: 87312428-ec0f-5990-9f69-6a269a041b4d)


@Configuration
@EnableSqs
public class CloudConfiguration {
    private static final Logger log = Logger.getLogger(CloudConfiguration.class);

    @MessageMapping("QUEUE")
    public void retrieveProvisionMessages(User user) {
        log.warn(user.firstName);
    }
}

YML
cloud:
    aws:
       credentials.accessKey: AccessKey
       credentials.secretKey: SecretKey
       region.static: us-west-2
       credentials.instanceProfile: true

当它尝试连接时,我看到 header 值为:
AWS4-HMAC-SHA256 Credential=accesskey/20150701/us-west-2/sqs/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=signature

请求发送后:
HTTP/1.1 403 Forbidden [Server: Server, Date: Wed, 01 Jul 2015 22:51:25 GMT, Content-Type: text/xml, Content-Length: 349, Connection: keep-alive, x-amzn-RequestId: Request Id] org.apache.http.conn.BasicManagedEntity@37e55df6

我已经检查了所有 AIM 政策,它们是正确的。

使用:
private AmazonSQS establishQueue(){
    AmazonSQS sqs = new AmazonSQSClient(new BasicAWSCredentials(accessKey, secretKey));
    sqs.setRegion(RegionUtils.getRegion(region));
    return sqs;
}


    AmazonSQS sqs = establishQueue();
    return sqs.receiveMessage(sqs.getQueueUrl(userProductPurchase).getQueueUrl());

使用相同的凭据工作正常。任何帮助是极大的赞赏。

谢谢

最佳答案

你有没有GetQueueAttributes您的 IAM 用户允许调用吗?

我认为它也使用了更多的操作。不仅ReceiveMessageGetQueueUrl .

关于Spring Cloud AWS SQS 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31173711/

相关文章:

spring - 使用 Spring 3 验证向导页面

java - Spring ApplicationContext Bean 接线

javascript - 解析云查询错误

.net - 云计算-Azure

java - 当两个应用程序都使用嵌入式 activemq 时如何将 Jms 消息从一个 spring-boot 应用程序发送到另一个

java - 我的 pom.xml 中有 javax.inject,spring 会自动使用它吗?

java - Spring Boot,使用 EhCache 进行缓存

azure - 地形错误:Unable to list provider registration status with azure

java - 为什么我在使用 RemoteFileTemplate 时会在日志中收到意外的 RuntimeException 警告?

java - 消息传递的幂等屏障