title: AuthorizationHeaderMalformed when trying to upload object to S3 via JS SDK
body: <p>I’m trying to upload an object to Amazon S3 via their JavaScript SDK, but getting the following error during the upload:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Error&gt;
      &lt;Code&gt;AuthorizationHeaderMalformed&lt;/Code&gt;
      &lt;Message&gt;The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-west-1'&lt;/Message&gt;
      &lt;Region&gt;eu-west-1&lt;/Region&gt;
      &lt;RequestId&gt;62D2D18E5093BF1D&lt;/RequestId&gt;
      &lt;HostId&gt;87ixJCkZyInIVI9BH4zdxtNzFuydwByK6ibvXOICXoE6ZQMp+lWf9RxetaL9c5qFEZEWW/RYdFQ=&lt;/HostId&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>I get this error response when a HTTP request to <a href="https://my-bucket-name.s3.amazonaws.com/?max-keys=0" rel="nofollow noreferrer">https://my-bucket-name.s3.amazonaws.com/?max-keys=0</a> is made.</p>
  
  <p>I’ve tried setting the region everywhere, but still getting the error.</p>
  
  <p>Here’s what my code instantiating the S3 client looks like:</p>
  
  <pre class="lang-js prettyprint-override"><code>import AWS from 'aws-sdk';
  
  AWS.config.update({
      region: 'eu-west-1',
      credentials: new AWS.CognitoIdentityCredentials({
          IdentityPoolId: this.identityPoolId
      }, {
          region: 'eu-west-1'
      })
  });
  
  this.s3 = new AWS.S3({
      apiVersion: '2006-03-01',
      params: {
          Bucket: this.bucket
      },
      region: 'eu-west-1'
  });
  </code></pre>
  
  <p>Where am I going wrong? Why is there still a reference to <code>us-east-1</code> in the above error response when generating the signature?</p>
  
  <p>EDIT: I’ve written and re-written the set-up code a few times over now. This is what I currently have:</p>
  
  <pre class="lang-js prettyprint-override"><code>const AWS = require('aws-sdk/global');
  const S3 = require('aws-sdk/clients/s3');
  
  this.s3 = new S3({
      apiVersion: 'latest',
      credentials: new AWS.CognitoIdentityCredentials({
          IdentityPoolId: this.identityPoolId
      }, {
          region: 'eu-west-1'
      }),
      params: {
          Bucket: this.bucket
      },
      region: 'eu-west-1'
  });
  </code></pre>
  
  <p>And then the code that does the actual file upload:</p>
  
  <pre class="lang-js prettyprint-override"><code>const params = {
      ACL: 'private',
      Body: this.file,
      ContentType: this.file.type,
      Key: `videos/input/${this.filename}`
  };
  
  this.s3
      .putObject(params)
      .on('httpUploadProgress', this.onUploadProgress)
      .send(this.onSend);
  </code></pre>