Spring Cloud AWS SQS AccessDenied
Currently, the connectivity issue is related to connecting to AWS SQS queue using Spring Cloud and Spring Boot. I believe everything is set up ok, but I get:
2015-07-01 18: 12: 11 926 [WARN] [-] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext [487] - Exception thrown during context initialization - attempt to update was canceled org.springframework.context.ApplicationContextException : failed start bean 'simpleMessageListenerContainer'; nested exception com.amazonaws.AmazonServiceException: Access to 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
When it tries to connect, I see that the header value is:
AWS4-HMAC-SHA256 Credential=accesskey/20150701/us-west-2/sqs/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=signature
After submitting the request:
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
I have checked all AIM policies and they are correct.
Using:
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());
with the same credentials works fine. Any help is appreciated.
thank
source to share