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 Oct 15, 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.

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
for (const table of Object.values(cfnResources.amplifyDynamoDbTables)) {
table.pointInTimeRecoveryEnabled = true;
}

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:

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
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:

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
cfnResources.amplifyDynamoDbTables["Todo"].timeToLiveAttribute = {
attributeName: "ttl",
enabled: true,
};

Example - Configure billing mode on a DynamoDB table

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

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { BillingMode } from "aws-cdk-lib/aws-dynamodb";
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
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".

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
cfnResources.amplifyDynamoDbTables["Todo"].provisionedThroughput = {
readCapacityUnits: 5,
writeCapacityUnits: 5,
};

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

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

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { data } from './data/resource';
const backend = defineBackend({
data
});
const { cfnResources } = backend.data.resources;
cfnResources.amplifyDynamoDbTables['Todo'].pointInTimeRecoveryEnabled = true;