10

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?

2 Answers 2

19

After some research, I found that 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

Will be more than happy if this can help someone. ;)

Sign up to request clarification or add additional context in comments.

1 Comment

I'm following these instructions to the point and i'm getting an error: code: 'InvalidARN', message: 'ARN region is empty'. Don't find any docs on it
1

When using the @aws-sdk/client-s3 package, the S3 client only needs the Wasabi endpoint defined. The following will create the S3 client w/ the correct endpoint:

const client = new S3Client({
    credentials: {
        accessKeyId: "<wasabi-access-key-id>",
        secretAccessKey: "<wasabi-secret-key>"
    },
    endpoint: {
        url: "https://s3.wasabisys.com"
    }
})

From here, putting an object is exactly the same as a standard AWS S3 bucket. Ex:

await client.send(new PutObjectCommand({
    Bucket: "bucket-name",
    Key: "object-key",
    Body: <whatever is being put>
})

With the basic import statement being:

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3"

1 Comment

Region is missing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.