Compoze Labs Blog | App Development, Data Engineering & AI Trends

Adding Custom Cognito SignUp Message | Compoze Labs

Written by Compoze Labs | Feb 25, 2022 2:30:00 PM

AWS Cognito is a secure and scalable user access management solution offered by Amazon Web Services. At Compoze Labs it is our go to solution for managing users when building apps in AWS.

Compoze is a platform that enables the rapid, secure, and scalable development of software products in AWS.

Custom Cognito Message

 

Cognito provides an easy way to send emails to your users during various user events such as: verifications, invitations, and MFA events.

However, if you want to add customization to these messages you need to create Lambda Triggers that fire during each of these events. These triggers can be executed during: pre-signup, pre-authentication, post-authentication, etc. The full list can be found in the AWS Docs.

For a recent app, we needed to implement a confirmation email when a user signed up. We wanted to have a custom link that the user would click, that would then redirect back to our app to confirm their user. In order to do this we needed to create a Lambda handler for the Custom Message Signup trigger .

Custom Message Trigger

 

In order to create this custom signup flow we needed to do the following:

  1. Create a custom Lambda Function to handle the Custom Message Trigger
  2. Update the Lambda Function to create our custom message with the generated confirmation link
  3. Update our Cognito instance to include the trigger (in our case we used Terraform to handle our Cognito configuration)

Create a custom Lambda Function to handle the Custom Message Trigger

 

The first thing we needed to do was create the Lambda project. With the Compoze CLI we quickly spun up our base Lambda project

Now we have a basic Lambda project configured with source code and a working deployment pipeline.

Update the Lambda Function to create our custom message with the generated confirmation link

Next, we need to create our Lambda Handler to be able to process the custom message triggers.

First we need to update our AWS SAM template with our function definition.

Once we have that, we need to create our Lambda Handler to generate our custom signup link and update the email message.

Then, we push and deploy!

Update our Cognito instance to include the trigger (in our case we used Terraform to handle our Cognito configuration)

Once our Lambda functions are deployed, we can update our Terraform module to contain the Lambda ARNs

 

After a simple terraform plan and terraform deploy we’re all set!

If you’re interested in learning more about how your team can leverage the Compoze CLI and the Compoze Platform reach out to us.