Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Page updated May 21, 2024

Extend S3 resources

For Amplify-generated S3 resources

Amplify Storage generates Amazon S3 resources to offer storage features. You can access the underlying Amazon S3 resources to further customize your backend configuration by using the AWS Cloud Developer Kit (AWS CDK).

Example - Enable Transfer Acceleration

The following is an example of how you would enable Transfer Acceleration on the bucket (CDK documentation). In order to enable Transfer Acceleration on the bucket, you will have to unwrap the L1 CDK construct from the L2 CDK construct like the following.

import * as s3 from 'aws-cdk-lib/aws-s3';
import { defineBackend } from '@aws-amplify/backend';
import { storage } from './storage/resource';
const backend = defineBackend({
storage
});
const s3Bucket = backend.storage.resources.bucket;
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket;
cfnBucket.accelerateConfiguration = {
accelerationStatus: "Enabled" // 'Suspended' if you want to disable transfer acceleration
}

Read more about escape hatches in the CDK.

For Manually configured S3 resources

To make calls to your S3 bucket from your App, you need to set up a CORS Policy for your S3 bucket. This callout is only for manual configuration of your S3 bucket.

The following steps will set up your CORS Policy:

  1. Go to Amazon S3 console and click on your project's userfiles bucket, which is normally named as [Bucket Name][Id]-dev. Go to [Amazon S3 Console]
  2. Click on the Permissions tab for your bucket. Click on the Permissions tab for your bucket
  3. Click the edit button in the Cross-origin resource sharing (CORS) section. Click the edit button in the Cross-origin resource sharing (CORS) section
  4. Make the Changes and click on Save Changes. You can add required metadata to be exposed in ExposeHeaders with x-amz-meta-XXXX format. Click on Save Changes:
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "HEAD", "PUT", "POST", "DELETE"],
"AllowedOrigins": ["*"],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2",
"ETag",
"x-amz-meta-foo"
],
"MaxAgeSeconds": 3000
}
]

Note: You can restrict the access to your bucket by updating AllowedOrigin to include individual domains.