I've been reading back and forth AWS documentations, but I am not able to find how to proper set the settings shown in the image below using cloudformation template. What I want to achieve is that, when a user signs up, Cognito sends an automatic email with a custom template presenting the user with the code to confirm its account.
The template.yml
below creates a resource with:
Allow Cognito to automatically send messages to verify and confirm
Disabled
And it looks like:
# Create Cognito UserPool (i.e., the table with the users)
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: auth-template-user-pool
UsernameAttributes:
- email
VerificationMessageTemplate:
DefaultEmailOption: CONFIRM_WITH_CODE
EmailConfiguration:
EmailSendingAccount: COGNITO_DEFAULT
Schema:
- Name: name
AttributeDataType: String
Mutable: true
Required: true
- Name: family_name
AttributeDataType: String
Mutable: true
Required: true
- Name: email
AttributeDataType: String
Mutable: false
Required: true
I thought the keys VerificationMessageTemplate
and EmailConfiguration
would do the job, but no email is received. However, when using the settings displayed in the image above, I do receive the confirmation code.
I think the key name (AutoVerifiedAttributes) for this feature is quite misleading since it may suggest that the attributes listed are auto-verified once a user has signed up.
Therefore, adding:
AutoVerifiedAttributes:
- email
does the job. Finally, the template must look like:
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: auth-template-user-pool
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
VerificationMessageTemplate:
DefaultEmailOption: CONFIRM_WITH_CODE
EmailConfiguration:
EmailSendingAccount: COGNITO_DEFAULT