This example shows how to use AWS SAM to create a user sign-up system (Cognito) and change the automatic emails it sends, like account verification or password reset emails. This is a great method if you want your application’s messages to match your brand’s style.
Project Components
The project has two main files:
cognito-email/index.js: This file contains a simple Lambda function. Its job is to change the content of the emails.template.yaml: This file tells AWS what to build. It includes:- Cognito User Pool: The place where user data is saved.
- Lambda Function: A simple function that runs when needed.
- Permissions: These allow Cognito to call the Lambda function.
How It Works
This setup customizes the email messages that Cognito sends in different user flows, such as:
- Signing up (email confirmation)
- Resetting a forgotten password
- Sending a confirmation code
Here’s how it works:
-
Cognito Triggers an Event
When a user signs up or resets their password, Cognito sends an event to the Lambda function. -
Lambda Customizes the Email
The function checks the event type (CustomMessage_SignUp,CustomMessage_ForgotPassword, etc.) and updates the subject and body of the email.
You can use plain text or full HTML to match your brand. -
Cognito Sends the Final Email
After the message is customized, Cognito sends the email to the user.
This way, all emails users receive (like verification and password reset) will look professional and consistent with your app’s design.
Project Repository: https://github.com/OmarMakled/sam-cognito-custom