Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Cognito's "Attribute verification and user account confirmation" from cloudformation

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.

AWS Cognito Attribute verification and user account confirmation

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.

like image 443
Andrea Nicolai Avatar asked Jan 18 '26 23:01

Andrea Nicolai


1 Answers

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
like image 111
Andrea Nicolai Avatar answered Jan 20 '26 13:01

Andrea Nicolai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!