JS AWS SDK - copyObject SignatureDoesNotMatch错误

时间:2016-07-11 16:55:44

标签: javascript amazon-s3 aws-sdk

我有一个使用Node和AWS-SDK包的应用程序。我使用copyObject方法将对象从一个桶复制到另一个桶。我收到的错误是SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.

我已经能够在本地计算机上成功运行代码,并将文件从一个存储桶复制到另一个存储桶。我在部署应用程序的AWS服务器上发生错误。完整的错误是:

{ [SignatureDoesNotMatch: The request signature we calculated does not 
match the signature you provided. Check your key and signing method.]
message: 'The request signature we calculated does not match the signature you provided. Check your key and signing method.',
code: 'SignatureDoesNotMatch',
region: null,
time: Mon Jul 11 2016 12:11:36 GMT-0400 (EDT),
requestId: <requestId>,
extendedRequestId: <extendedRequestId>,
cfId: undefined,
statusCode: 403,
retryable: false,
retryDelay: 66.48076744750142 }

此外,我能够执行listObjects命令。该错误仅发生在copyObject上。 到目前为止,我已经尝试了

  • correctClockSkew设为true
  • 检查服务器时间(与本地计算机相同)
  • 检查了密钥/密钥(从配置文件加载并在本地工作)
  • 检查了文件名(没有奇怪的字符。字母数字,&#39;。&#39;,&#39; - &#39;和&#39; /&#39;)

以下是导致问题的代码:

AWS.config.update({
  accessKeyId: <accessKeyId>,
  secretAccessKey: <secretAccessKey>,
  correctClockSkew: true
});
var s3 = new AWS.S3();
var params = {
  Bucket: <bucket>,
  Prefix: <prefix>
};

s3.listObjects(params, function(err, data) {
  if (data.Contents.length) {
    async.each(data.Contents, function(file, cb) {
      var file_name = file.Key.substr(file.Key.indexOf('/')+1);
      var copy_params = {
        Bucket: <bucket2>,
        CopySource: <bucket> + '/' + file.Key,
        Key: file_name,
        ACL: 'public-read'
      };

      s3.copyObject(copy_params, function(copyErr, copyData){
        if (copyErr) {
          console.log('Error:', copyErr);
        }
        else {
          cb();
        }
      });
    }, function(err){
        ...
      }
    });
  } else {
    ...
  }
});

0 个答案:

没有答案