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

Page updated Apr 5, 2024

Modify Amplify-generated AWS resources

Amplify GraphQL API uses a variety of auto-generated, underlying AWS services and resources. You can customize these underlying resources to optimize the deployed stack for your specific use case.

In your Amplify app, you can access every underlying resource using CDK "L2" or "L1" constructs. Access the generated resources as L2 constructs via the .resources property on the returned stack or access the generated resources as L1 constructs using the .resources.cfnResources property.

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3
4const backend = defineBackend({
5 data
6});
7
8const dataResources = backend.data.resources;
9
10Object.values(dataResources.cfnResources.amplifyDynamoDbTables).forEach((table) => {
11 table.pointInTimeRecoveryEnabled = true;
12});

Customize Amplify-generated AppSync GraphQL API resources

Apply all the customizations on backend.data.resources.graphqlApi or backend.data.resources.cfnResources.cfnGraphqlApi. For example, to enable X-Ray tracing for the AppSync GraphQL API:

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3
4const backend = defineBackend({
5 data
6});
7
8const dataResources = backend.data.resources;
9
10dataResources.cfnResources.cfnGraphqlApi.xrayEnabled = true;

Customize Amplify-generated resources for data models

Pass in the model type name into backend.data.resources.amplifyDynamoDbTables["MODEL_NAME"] to modify the resources generated for that particular model type. For example, to enable time-to-live on the Todo @model type's DynamoDB table:

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3
4const backend = defineBackend({
5 data
6});
7
8const dataResources = backend.data.resources;
9
10dataResources.cfnResources.amplifyDynamoDbTables["Todo"].timeToLiveAttribute = {
11 attributeName: "ttl",
12 enabled: true,
13};

Example - Configure billing mode on a DynamoDB table

Set the DynamoDB billing mode for the DynamoDB table as either "PROVISIONED" or "PAY_PER_REQUEST".

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3import { BillingMode } from "aws-cdk-lib/aws-dynamodb";
4
5const backend = defineBackend({
6 data
7});
8const dataResources = backend.data.resources;
9
10dataResources.cfnResources.amplifyDynamoDbTables['Todo'].billingMode = BillingMode.PAY_PER_REQUEST;

Example - Configure provisioned throughput for a DynamoDB table

Override the default ProvisionedThroughput provisioned for each model table and its Global Secondary Indexes (GSI). This override is only valid if the "DynamoDBBillingMode" is set to "PROVISIONED".

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3
4const backend = defineBackend({
5 data
6});
7
8const dataResources = backend.data.resources;
9
10dataResources.cfnResources.amplifyDynamoDbTables["Todo"].provisionedThroughput = {
11 readCapacityUnits: 5,
12 writeCapacityUnits: 5,
13};

Example - Enable point-in-time recovery for a DynamoDB table

Enable/disable DynamoDB point-in-time recovery for each model table.

1import { defineBackend } from '@aws-amplify/backend';
2import { data } from './data/resource';
3
4const backend = defineBackend({
5 data
6});
7
8const dataResources = backend.data.resources;
9
10dataResources.cfnResources.amplifyDynamoDbTables['Todo'].pointInTimeRecoveryEnabled = true;