Turistforeningen / node-s3-uploader

Flexible and efficient resize, rename, and upload images to Amazon S3 disk storage. Uses the official AWS Node SDK for transfer, and ImageMagick for image processing. Support for multiple image versions targets.
https://www.npmjs.com/package/s3-uploader
MIT License
241 stars 54 forks source link

The authorization mechanism you have provided is not supported #125

Open isaacguerreir opened 7 years ago

isaacguerreir commented 7 years ago

Subject of the issue

Appear a error. InvalidRequest: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

What is that?

Your environment

Steps to reproduce

Tell us how to reproduce this issue. Please provide a minimal code example to demonstrate the problem.

// your code here

Expected behaviour

Tell us what should happen.

Actual behaviour

Tell us what happens instead.

// log outoput or error messages here
Starefossen commented 7 years ago

Hi @isaacguerreir, could you fill out the rest of the template and I'll be happy to debug the problem with you 😊

flxbe commented 7 years ago

Hey guys,

I had the same issue after I initialized my AWS-credentials directly with the sdk and not explicitly passing them to the s3-uploader.

The problem here is that the s3-uploader always sets the aws-region when creating the S3-object. This is us-east-1 by default, which still supports the old aws-signature-version v2. However, newer regions do not support it anymore. You therefore always have to explicitly set your aws-region when initializing the Upload-object:

const client = new Upload("bucket", {
  aws: {
    region: "eu-central-1"
  },
  /**
  * ...
  **/
})

This solved the issue for me. Seems to me as if the aws-sdk still uses the endpoint you specified when updating your sdk-configuration although one can specify an alternative region when creating the S3-object. Anyway I hope this helps you as well.

azkarmoulana commented 6 years ago

@isaacguerreir it's because you are using the old aws signature version v2. You can prevent this error by moving to new aws signature version v4.

when initializing your s3 client pass this signatureVersion: 'v4' as a parameter.

let s3bucket = new AWS.S3({ accessKeyId: IAM_USER_KEY, secretAccessKey: IAM_USER_SECRET, Bucket: BUCKET_NAME, signatureVersion: 'v4' },);