title: SignatureDoesNotMatch in AWS Java SDK for S3
body: <p>I have a bucket belonging to another account.
  Using the AWS CLI I am able to access (list and read objects) this bucket.
  For example:</p>
  
  <pre><code>aws s3 ls s3://somebucket/foo/bar
  </code></pre>
  
  <p>Lists the objects.</p>
  
  <p>Trying to recreate the same using the Java SDK (in Scala) I am getting the above exception (SignatureDoesNotMatch).</p>
  
  <p>Here is the code:</p>
  
  <pre><code>package com.myco.sample
  
  class TestCase() {
      val credentials = new com.amazonaws.auth.BasicAWSCredentials(
          "ACCESS_KEY_ID", 
          "SECRET_ACCESS_KEY"
      )
      val s3 = new com.amazonaws.services.s3.AmazonS3Client(credentials)
      val endpoint = "somebucket.s3-us-west-2.amazonaws.com"
      s3.setEndpoint(endpoint)
  
      try {
          val objs = s3.listObjects("foo/bar")
      } catch {
          case ace: com.amazonaws.services.s3.model.AmazonS3Exception =&gt; {
              println(ace.getAdditionalDetails)
          }
      }
  }
  </code></pre>
  
  <p>The call to listObjects throws an exception.
  The output is:</p>
  
  <pre><code>com.amazonaws.services.s3.model.AmazonS3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method. (Service: Amazon S3; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: XXXXXXXXX), S3 Extended Request ID: XXXXXXXXXXXXXXXXXXX=
  {SignatureProvided=XXXXXXXXXXXXX=, StringToSign=Wed, 06 Jan 2016 04:32:38 GMT
  /somebucket/foo/bar/, AWSAccessKeyId=XXXXXX, Error=XXXXXXXXXXXX=, StringToSignBytes=XXXXXXXXX}
  </code></pre>
  
  <p>When not providing the endpoint as above, I am getting a different error:
  <code>The bucket you are attempting to access must be addressed using the specified endpoint</code></p>
  
  <p>After setting the endpoint, I've tried multiple ways of passing the "bucket" parameter to listObjects, all of which didn't work.</p>
  
  <p>Not sure why the signature that's being generated behind the scenes is incorrect. Any ideas?</p>