title: Spring Cloud AWS SQS AccessDenied
body: <p>I am currently having a connection issue trying to connect to an AWS SQS Queue using Spring Cloud and Spring Boot.  I believe I have everything configured fine but am getting:</p>
  
  <blockquote>
    <p>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
    <a href="https://sqs.us-west-2.amazonaws.com/" rel="nofollow">https://sqs.us-west-2.amazonaws.com/</a>{Number}/{Queue Name} is denied.
    (Service: AmazonSQS; Status Code: 403; Error Code: AccessDenied;
    Request ID: 87312428-ec0f-5990-9f69-6a269a041b4d)</p>
  </blockquote>
  
  <pre><code>@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);
      }
  }
  </code></pre>
  
  <p>YML</p>
  
  <pre><code>cloud:
      aws:
         credentials.accessKey: AccessKey
         credentials.secretKey: SecretKey
         region.static: us-west-2
         credentials.instanceProfile: true
  </code></pre>
  
  <p>When it attempts to connect I see that a header value of:</p>
  
  <pre><code>AWS4-HMAC-SHA256 Credential=accesskey/20150701/us-west-2/sqs/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=signature
  </code></pre>
  
  <p>After the request is sent:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have checked all AIM policies and they are correct.  </p>
  
  <p>Using:</p>
  
  <pre><code>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());
  </code></pre>
  
  <p>with the same credentials works fine.  Any help is greatly appreciated.</p>
  
  <p>Thanks</p>