- Newest
- Most votes
- Most comments
To customize email verification code and sending address per user in your Amazon Cognito user pool using SES, you'll need to implement a Custom Email Sender Lambda trigger. Here are the steps to implement your flow:
- First, set up your Amazon SES configuration:
- Verify your email addresses or domain with Amazon SES
- Move out of the SES sandbox if needed for production use
- Create appropriate sending authorization policies
- Configure your user pool email settings:
- In the Amazon Cognito console, go to your user pool
- Navigate to "Authentication methods" menu
- Locate "Email configuration" and choose "Edit"
- Select "Send email from Amazon SES" option
- Configure your SES Region and other settings
- Create a Custom Email Sender Lambda function:
- Create a new Lambda function that will handle the email customization
- The function will receive event data including user attributes and code
- Implement your logic to:
- Extract the username from the event
- Connect to your database
- Select the appropriate sending address based on user attributes
- Use the AWS SDK to send the email via SES with your custom FROM address
- Include the verification code in the email (available in the encrypted code parameter)
- Configure the Lambda trigger:
- In the Amazon Cognito console, go to your user pool
- Navigate to the "User pool properties" section
- Under "Lambda triggers", add your function as a "Custom email sender" trigger
Your Lambda function will receive parameters including:
triggerSource: Identifies the event type (e.g., "CustomEmailSender_SignUp" for verification during sign-up)request.userAttributes: Contains user attributes including emailrequest.code: Contains the encrypted verification coderequest.clientMetadata: Any custom metadata provided during sign-up
The function must decrypt the code and handle sending the email via SES. You'll need to return the event object back to Amazon Cognito when complete.
Note that the verification code is valid for 24 hours, and your custom function is responsible for all email delivery from your user pool. The maximum length for verification messages is 20,000 UTF-8 characters, and you can include HTML formatting in your emails.
Sources
Configuring MFA, authentication, verification and invitation messages - Amazon Cognito
Email settings for Amazon Cognito user pools - Amazon Cognito
Custom email sender Lambda trigger - Amazon Cognito
Relevant content
- asked 3 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 months ago
