Override Amplify-generated Cognito resources
amplify override auth
Run the command above to override Amplify-generated auth resources including Amazon Cognito user pool, identity pool, user pool groups, and more.
The command creates a new overrides.ts
file under amplify/backend/auth/<resource-name>/
which provides you the Amplify-generated resources as CDK constructs.
Customize Amplify-generated Cognito auth resources
Apply all the overrides in the override(...)
function. For example, to update the temporary password validity days for your Cognito user pool:
import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyAuthCognitoStackTemplate) { resources.userPool.policies = { // Set the user pool policies passwordPolicy: { ...resources.userPool.policies["passwordPolicy"], // Carry over existing settings temporaryPasswordValidityDays: 3 // Add new setting not provided Amplify's default } }}
Or add a custom attribute to your Cognito user pool:
import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper'
export function override(resources: AmplifyAuthCognitoStackTemplate) { const myCustomAttribute = { attributeDataType: 'String', developerOnlyAttribute: false, mutable: true, name: 'my_custom_attribute', required: false, } resources.userPool.schema = [ ...(resources.userPool.schema as any[]), // Carry over existing attributes (example: email) myCustomAttribute, ]}
You can override the following auth resources that Amplify generates:
Amplify-generated resource | Description |
---|---|
customMessageConfirmationBucket | S3 bucket used for custom message triggers |
snsRole | SNS role for sending authentication-related messages |
userPool | The Cognito user pool that enables user sign-up and sign-in |
userPoolClientWeb | A Cognito user pool client for web apps |
userPoolClient | A Cognito user pool client for mobile apps |
identityPool | A Cognito identity pool to federate identities |
identityPoolRoleMap | Role mapping for authenticated and unauthenticated user roles |
lambdaConfigPermissions | Permissions for Lambda function to access Cognito user pool and identity pool |
lambdaTriggerPermissions | IAM policy attached to Cognito Lambda triggers |
userPoolClientLambda | Lambda function to fetch app client secret from user pool client |
userPoolClientRole | IAM Role for Lambda function to fetch app client secret from user pool client |
userPoolClientLambdaPolicy | IAM Policy for Lambda function to fetch app client secret from user pool client |
userPoolClientLogPolicy | IAM Policy to enable CloudWatch logging for Lambda function to fetch app client secret from user pool client |
userPoolClientInputs | Custom CloudFormation resource to fetch app client secret from user pool client |
hostedUICustomResource | Lambda function to enable Cognito user pool Hosted UI login |
hostedUICustomResourcePolicy | IAM Policy for Lambda function to enable Cognito user pool Hosted UI login |
hostedUICustomResourceLogPolicy | IAM Policy to enable CloudWatch logging for Lambda function to enable Cognito user pool Hosted UI login |
hostedUICustomResourceInputs | Custom CloudFormation resource to enable Cognito user pool Hosted UI login |
hostedUIProvidersCustomResource | Lambda function to configure Hosted UI with 3rd party identity providers |
hostedUIProvidersCustomResourcePolicy | IAM Policy for Lambda function to configure Hosted UI with 3rd party identity provider |
hostedUIProvidersCustomResourceLogPolicy | IAM Policy to enable CloudWatch logging for Lambda function to configure Hosted UI with 3rd party identity provider |
hostedUIProvidersCustomResourceInputs | Custom CloudFormation resource to configure Hosted UI with 3rd party identity provider |
oAuthCustomResource | Lambda function to enable OAuth |
oAuthCustomResourcePolicy | IAM Policy for OAuth custom CloudFormation resource |
oAuthCustomResourceLogPolicy | IAM Policy to enable CloudWatch logging for OAuth Lambda function |
oAuthCustomResourceInputs | Custom CloudFormation resource to enable OAuth |
mfaLambda | Lambda function to enable multi-factor authentication function |
mfaLogPolicy | IAM Policy to enable CloudWatch logging for multi-factor authentication Lambda function |
mfaLambdaPolicy | IAM Policy for multi-factor authentication Lambda function |
mfaLambdaInputs | Custom CloudFormation resource to enable multi-factor authentication |
mfaLambdaRole | IAM Execution Role for multi-factor authentication Lambda function |
openIdLambda | Lambda function to enable OpenID Connect |
openIdLogPolicy | IAM Policy to enable CloudWatch logging for OpenID Connect Lambda function |
openIdLambdaIAMPolicy | IAM Policy to enable OpenID Connect Lambda function |
openIdLambdaInputs | Custom CloudFormation resource to enable OpenID Connect |
openIdLambdaRole | Lambda Execution Role for OpenID Connect Lambda function |
Customize Amplify-generated Cognito user group resources
Apply all the overrides in the override(...)
function. For example to add a path to the lambda execution role that facilitates the user pool group to role mapping:
import { AmplifyUserPoolGroupStackTemplate } from '@aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyUserPoolGroupStackTemplate) { resources.lambdaExecutionRole.path = "/<my-path>/" // Note: CFN does not allow you to modify the path after creation}
You can override the following user pool group resources that Amplify generates:
Amplify-generated resource | Description |
---|---|
userPoolGroup | The map of user pool groups |
userPoolGroupRole | The map of user pool group roles |
roleMapCustomResource | A custom CloudFormation resource to map user pool groups to their roles |
lambdaExecutionRole | Lambda execution role for the "user pool group"-to-role mapping function |
roleMapLambdaFunction | The Lambda function that facilitates the user pool group to role mapping |
Customize Amplify-generated Cognito auth resources with social providers
Apply all the overrides in the override(...)
function. For example to add social providers to your Cognito user pool:
import { AmplifyAuthCognitoStackTemplate } from "@aws-amplify/cli-extensibility-helper";
export function override(resources: AmplifyAuthCognitoStackTemplate) { resources.addCfnResource( { type: "AWS::Cognito::UserPoolIdentityProvider", properties: { AttributeMapping: { preferred_username: "email", email: "email" }, ProviderDetails: { client_id: "test", client_secret: "test", authorize_scopes: "test", }, ProviderName: "LoginWithAmazon", ProviderType: "LoginWithAmazon", UserPoolId: { Ref: "UserPool", }, }, }, "amazon-social-provider" );}