Page updated Nov 20, 2023

Overriding resources

When defining resources you can access some underlying AWS CDK construct props to modify resource configurations.

Customize Cognito UserPool email verification settings

import { defineAuth } from "@aws-amplify/backend"; export const auth = defineAuth({ loginWith: { email: { verificationEmailStyle: "CODE", verificationEmailBody: (code: string) => `Welcome! Your verification code is ${code}.`, verificationEmailSubject: "Welcome! Here is your verification code", }, }, });
1import { defineAuth } from "@aws-amplify/backend";
2
3export const auth = defineAuth({
4 loginWith: {
5 email: {
6 verificationEmailStyle: "CODE",
7 verificationEmailBody: (code: string) =>
8 `Welcome! Your verification code is ${code}.`,
9 verificationEmailSubject: "Welcome! Here is your verification code",
10 },
11 },
12});

Alternatively you can mutate the synthesized CDK constructs directly after setting them on your backend:

Override Cognito UserPool password policies

import { Backend } from '@aws-amplify/backend'; import { auth } from './auth/resource'; const backend = new Backend({ auth, }); // override userpool password policies backend.resources.auth.resources.cfnResources.cfnUserPool.addPropertyOverride( "Policies", { PasswordPolicy: { MinimumLength: 10, RequireLowercase: true, RequireNumbers: true, RequireSymbols: true, RequireUppercase: true, TemporaryPasswordValidityDays: 20, }, } );
1import { Backend } from '@aws-amplify/backend';
2import { auth } from './auth/resource';
3
4const backend = new Backend({
5 auth,
6});
7
8// override userpool password policies
9backend.resources.auth.resources.cfnResources.cfnUserPool.addPropertyOverride(
10 "Policies",
11 {
12 PasswordPolicy: {
13 MinimumLength: 10,
14 RequireLowercase: true,
15 RequireNumbers: true,
16 RequireSymbols: true,
17 RequireUppercase: true,
18 TemporaryPasswordValidityDays: 20,
19 },
20 }
21);

Below are additional example scenarios where you may want to override resources.

Add tags to resources

Amplify Data's underlying GraphQL API

import { defineBackend } from "@aws-amplify/backend"; import { auth } from "./auth/resource.js"; import { data } from "./data/resource.js"; const backend = defineBackend({ auth, data, }); backend.resources.data.resources.cfnResources.cfnGraphqlApi.addPropertyOverride( "Tags", [ { Key: "graphqlapi-tag-1", Value: "graphql-tag-value-1", }, { Key: "graphqlapi-tag-2", Value: "graphql-tag-value-2", }, ] );
1import { defineBackend } from "@aws-amplify/backend";
2import { auth } from "./auth/resource.js";
3import { data } from "./data/resource.js";
4
5const backend = defineBackend({
6 auth,
7 data,
8});
9
10backend.resources.data.resources.cfnResources.cfnGraphqlApi.addPropertyOverride(
11 "Tags",
12 [
13 {
14 Key: "graphqlapi-tag-1",
15 Value: "graphql-tag-value-1",
16 },
17 {
18 Key: "graphqlapi-tag-2",
19 Value: "graphql-tag-value-2",
20 },
21 ]
22);