Search code examples
node.jsamazon-web-servicesamazon-s3knox-amazon-s3-client

Amazon S3 PUT throws "SignatureDoesNotMatch"


This AWS security stuff is driving me nuts. I'm trying to upload some binary files from a node app using knox. I keep getting the infamous SignatureDoesNotMatch error with my key/secret combination. I traced it down to this: with e.g. Transmit, I can access the bucket by connecting to s3.amazonaws.com, but I cannot access it via the virtual subdomain mybucket.s3.amazonaws.com. (When I try to access the bucket with the s3.amazonaws.com/mybucket syntax, I get an error saying that only the subdomain style is allowed.)

I have tried setting the bucket policy to explicitly allow PUT from the respective user, but that had no effect. Can anyone please shed some light on how I can enable uploading of files from one specific AWS user?


Solution

  • After a lot of trial and error, I narrowed it down to a couple of issues. I'm not entirely sure which one ultimately fixed it, but here are a few things you might want to try:

    • make sure you are setting the right datacenter. In my case, this looked like this:

      knox.createClient({
             key: this.config.key
        , secret: this.config.secret
        , bucket: this.config.bucket
        , region: 'us-west-2' // cause my bucket is supposed to be in oregon
      });
      
    • Check your PUT headers. In my case, the Content-Type was accidentally set to undef which caused issues:

      var headers = {
          'x-amz-acl': 'public-read' // if you want anyone to be able to download the file
      };
      if (filesize) headers['Content-Length'] = filesize;
      if (mime) headers['Content-Type'] = mime;