Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload file into Wasabi bucket with s3 api with node.js?

I implemented uploading file in Amazon s3 bucket like below and it works fine:


  const S3 = require('aws-sdk/clients/s3');
  const AWS = require('aws-sdk');

  const accessKeyId = 'AKIAYVXDX*******';
  const secretAccessKey = 'gxZpdSDnOfpM*****************';

  const s3 = new S3({
    region: 'us-east-1',
    accessKeyId,
    secretAccessKey
  });

  s3.putObject({
      Body: 'Hello World',
      Bucket: "dev-amazon",
      Key: 'hello.txt'
    }
    , (err, data) => {
      if (err) {
         console.log(err);
      }
    });

And I need to implement uploading file in Wasabi bucket.

I tried like below:


  const S3 = require('aws-sdk/clients/s3');
  const AWS = require('aws-sdk');
  const wasabiEndpoint = new AWS.Endpoint('s3.wasabisys.com');

  const accessKeyId = 'PEIL4DYOY*******';
  const secretAccessKey = 'D4jIz3tjJw*****************';

  const s3 = new S3({
    endpoint: wasabiEndpoint,
    region: 'us-east-2',
    accessKeyId,
    secretAccessKey
  });

  s3.putObject({
      Body: 'Hello World',
      Bucket: "dev-wasabi",
      Key: 'hello.txt'
    }
    , (err, data) => {
      if (err) {
         console.log(err);
      }
    });

And the result of `console.log(err) is:

err {"message":"The request signature we calculated does not match the signature you provided. Check your key and signing method.","code":"SignatureDoesNotMatch","region":null,"time":"2019-10-30T09:39:19.072Z","requestId":null,"statusCode":403,"retryable":false,"retryDelay":64.72166771381391}

Console error in devtools:

PUT https://dev-wasabi.s3.us-east-2.wasabisys.com/5efa9b286821fab7df3ece8dc3d6687ed32 403 (Forbidden)

What is wrong in my codes?

like image 884
Diamond Avatar asked Oct 30 '19 09:10

Diamond


1 Answers

I found the reason of this issue myself.

wasabiEndpoint was wrong. It should be

  const wasabiEndpoint = new AWS.Endpoint('s3.us-east-2.wasabisys.com ');

According to docs, service URLs should be different based on regions.

Wasabi US East 1 (N. Virginia): s3.wasabisys.com or s3.us-east-1.wasabisys.com

Wasabi US East 2 (N. Virginia): s3.us-east-2.wasabisys.com

Wasabi US West 1 (Oregon): s3.us-west-1.wasabisys.com

Wasabi EU Central 1 (Amsterdam): s3.eu-central-1.wasabisys.com

I will be very grateful if this helps someone. :)

like image 90
Diamond Avatar answered Oct 11 '22 06:10

Diamond