title: S3 Multipart upload via cloudfront distribution with aws-sdk-js
body: <p>I'm trying to make an multipart upload using cloudfront as an endpoint, I know this is possible ( <a href="https://github.com/aws/aws-sdk-js/issues/423" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-js/issues/423</a> ), and I've also opened a ticket on the Github of aws-sdk-js, I don't know if I'm missing some configuration option, or something else, but I'm not able to do an upload trough Cloufront using the aws sdk multipart upload functions, I always get 503's on the PUT requests.</p>
  
  <pre><code>&lt;Error&gt;
  &lt;Code&gt;SignatureDoesNotMatch&lt;/Code&gt;
  &lt;Message&gt;The request signature we calculated does not match the signature you provided. Check your key and signing method.&lt;/Message&gt;
  &lt;AWSAccessKeyId&gt;...&lt;/AWSAccessKeyId&gt;
  &lt;StringToSign&gt;POST
  
  application/octet-stream; charset=UTF-8
  
  x-amz-acl:private
  x-amz-date:Tue, 28 Jul 2015 15:22:01 GMT
  x-amz-user-agent:aws-sdk-js/2.1.40
  /bucket-name/test_797965294&lt;/StringToSign&gt;
  &lt;SignatureProvided&gt;...&lt;/SignatureProvided&gt;
  &lt;StringToSignBytes&gt;....&lt;/StringToSignBytes&gt;&lt;RequestId&gt;7488F0A2F70E4AC5&lt;/RequestId&gt;
  &lt;HostId&gt;...&lt;/HostId&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>I'm using the following code start the multi-part upload:</p>
  
  <pre><code>AWS.config.update({
      accessKeyId: 'XXXXXXXXXXXXXXXXX',
      secretAccessKey: 'XXXXXXXXXXXXXXXXXX'
  });
  
  var s3Client = new AWS.S3({
      endpoint: 'XXXXXXXX.cloudfront.net',
      s3BucketEndpoint: true,
      region: 'eu-west-1'
  });
  
  var TEMP_filename = 'test_' + Math.floor(1000000000*Math.random());
  
  var params = {
      Bucket: 'bucket-name',
      Key: TEMP_filename, 
      ACL: 'private'
  };
  
  s3Client.createMultipartUpload(params, function(err, data) {
      if (err) {
          console.log(err, err.stack); // an error occurred
      } else {
          console.log(data);           // successful response
      }
  });
  </code></pre>
  
  <p>And the result is:
  <a href="https://i.stack.imgur.com/hm2mR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hm2mR.png" alt="Network output from google console"></a></p>
  
  <p><a href="https://i.stack.imgur.com/zpXmP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zpXmP.jpg" alt="Request detail"></a></p>
  
  <p>Am I missing something in the configuration of the client?</p>
  
  <p>It's also worth to mention, that when using, AWS.S3.ManagedUpload, almost everything works perfectly. If the file size is smaller than the required to make an multipart upload, everything goes ok, but when switching to an multipart upload everything breaks again. It's always on the POST requests, the PUT requests seem to work fine.</p>
  
  <p>The only way this seems to work, is using the <code>putObject</code>, function using this I don't have any problem whatsoever, but I need resume support, and that can only be achieved trough the multipart upload.</p>
  
  <p>BTW, I'm using the latest version of the SDK: aws-sdk-js/2.1.40</p>