Modify Amplify-generated resources
Amplify Storage uses underlying AWS services and resources such as S3 and DynamoDB. You can customize these underlying resources for your specific use case.
amplify override storage
Run the command above to override Amplify-generated storage resources including the S3 bucket, DynamoDB tables, and more.
The command creates a new overrides.ts
file under amplify/backend/storage/<resource-name>/
which provides you the Amplify-generated resources as CDK constructs.
Customize Amplify-generated S3 resources
Apply all the overrides in the override(...)
function. For example to enable versioning on your S3 bucket:
import { AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyS3ResourceTemplate) { resources.s3Bucket.versioningConfiguration = { status: 'Enabled' };}
You can override the following S3-related resources that Amplify generates:
Amplify-generated resource | Description |
---|---|
s3Bucket | The S3 bucket that Amplify generates for file storage upon amplify add storage |
s3AuthPublicPolicy | The IAM policy for authenticated users' write access to public/* prefix |
s3AuthProtectedPolicy | The IAM policy for authenticated users' write access to protected/* prefix |
s3AuthPrivatePolicy | The IAM policy for authenticated users' write access to private/* prefix |
s3AuthUploadPolicy | The IAM policy for authenticated users' write access to uploads/* prefix |
s3AuthReadPolicy | The IAM policy for authenticated users' read access |
s3GuestPublicPolicy | The IAM policy for guest users' write access to public/* prefix |
s3GuestUploadPolicy | The IAM policy for guest users' write access to uploads/* prefix |
s3GuestReadPolicy | The IAM policy for guest users' read access |
For example, you can use amplify override storage
to add additional PUT and GET access IAM policy statements to the S3 bucket's default public Auth policy:
import { AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyS3ResourceTemplate) { resources.s3AuthPublicPolicy.policyDocument.Statement = [ ...resources.s3AuthPublicPolicy.policyDocument.Statement, { Effect: 'Allow', Action: ['s3:PutObject', 's3:PutObjectAcl', 's3:GetObject'], Resource: '<ARN of the S3 resource>' } ];}
Please refer to the IAM documentation for more information on actions, resources, and condition keys for Amazon S3.
Customize Amplify-generated DynamoDB tables
Apply all the overrides in the override(...)
function. For example to enable time-to-live specification on your DynamoDB table:
import { AmplifyDDBResourceTemplate } from '@aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyDDBResourceTemplate) { resources.dynamoDBTable.timeToLiveSpecification = { attributeName: 'ttl', enabled: true };}
You can override the following DynamoDB resources that Amplify generates:
Amplify-generated resource | Description |
---|---|
dynamoDBTable | The DynamoDB table that Amplify creates upon amplify add storage |