Tom
Tom

Reputation: 8127

How to configure AWS Amplify's Storage.put to use a transfer accelerated s3 bucket domain?

I've enabled S3 Transfer Acceleration using Cloudformation.

The documentation says that after enabling it, developers need to point their clients to use the new accelerated domain name.

E.g. from mybucket.s3.us-east-1.amazonaws.com to bucketname.s3-accelerate.amazonaws.com.

However, AWS Amplify's Storage.put method is using the bucket name defined during configuration like so:

Amplify.configure({
  Storage: {
    AWSS3: {
      bucket: AWS_BUCKET_NAME,
      region: AWS_REGION
    }
  }
})

Since there is no domain name here, but only a bucket name, how does one set it to access the accelerated endpoint instead?

Upvotes: 1

Views: 1264

Answers (2)

Nathan H
Nathan H

Reputation: 56

I also was struggling with this and stumbled on now to enable this with Storage.put:

  1. Specify your normal bucket name, as you normally would
  2. In the options object for Storage.put, set useAccelerateEndpoint: true (which I took from the above answer)

If you do a test, and look at the network console for the Chrome Developer Tools, you will see that Amplify specifies the correct path for the accelerated endpoint.

Upvotes: 0

Gabriele Mastrapasqua
Gabriele Mastrapasqua

Reputation: 159

It's seems to me that Amplify Storage doesn't support this configuration out of the box, so if you want to use Transfer Acceleration you will need to use the standard S3 client for javascript like so:

// obtain credentials from cognito to make uploads to s3...
let albumBucketName = "BUCKET_NAME";
let bucketRegion = "REGION";
let IdentityPoolId = "IDENTITY_POOL_ID";

AWS.config.update({
region: bucketRegion,
credentials: new AWS.CognitoIdentityCredentials({
    IdentityPoolId: IdentityPoolId
})
});

// configure the S3 client to use accelerate - note useAccelerateEndpoint flag
const options = {
    signatureVersion: 'v4',
    region: bucketRegion, // same as your bucket
    endpoint: new AWS.Endpoint('your-bucket-name.s3-accelerate.amazonaws.com'),    
    useAccelerateEndpoint: true,  
};
const s3 = new AWS.S3(options);

// then use the client...
// ...

Reference for the class AWS.S3: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html

Upvotes: 1

Related Questions