Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cognito Custom Message Trigger doesn't have any effect

I am trying to customize the message sent to the user pre-verification by using the custom message trigger, I verified that the data returned from the lambda is valid and the modifications are as I want them to be, however it seems that those changes are not taking any effect as I get the standard verification details to my email

I failed to find any solutions in aws docs, anyone had the same issue ?

    package main

import (
    "fmt"

    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
)

// Handler will handle our request comming from the API gateway
func Handler(event events.CognitoEventUserPoolsCustomMessage) (events.CognitoEventUserPoolsCustomMessage, error) {

    if event.TriggerSource == "CustomMessage_SignUp" {
        event.Response.EmailMessage = "Welcome to myapp, please click the following link to verify your email, this is a custom message"
        event.Response.EmailMessage = fmt.Sprintf(`Please click the link below to verify your email address. https://apigateway.myapp.com/auth/validate?client_id=%s&user_name=%s&confirmation_code=%s`, event.CallerContext.ClientID, event.UserName, event.Request.CodeParameter)
    }

    return event, nil
}

func main() {
    lambda.Start(Handler)
}
like image 992
Smail Galijasevic Avatar asked Jan 05 '20 20:01

Smail Galijasevic


People also ask

How to customize the default email messages provided by Cognito?

Since the default email is very plain, is quite common to have to provide a custom implementation. In order to customize the default email messages provided by cognito is by creating a Custom message lambda trigger. Let's implement the entry point of our Custom Message trigger function:

How do I trigger a Lambda trigger in Amazon Cognito?

Amazon Cognito can invoke a Lambda trigger at multiple events: post-registration, resending a verification code, recovering a forgotten password, or verifying a user attribute. The response includes messages for both SMS and email. The message must include the code parameter "####".

What is the difference between a custom message and a trigger?

Custom message – When a user's email or phone number is changed, this trigger sends a verification code automatically to the user. Cannot be used for other attributes. Custom message – This trigger sends a verification code to the user when they manually request it for a new email or phone number.

How to configure custom message customization on AWS Cognito?

Message Customization on Cognito 1 Ways to configure message customization 2 AWS Console. In AWS Console, when can navigate to AWS Cognito User Pool and select the user pool you want to edit and navigate to the "Message Customization" tab. 3 AWS CLI. ... 4 Custom message via Lambda function trigger. ...


2 Answers

It seems that in the cognito panel under message customizations verification type code needs to be checked (not link), after I did that the trigger does change the message

like image 92
Smail Galijasevic Avatar answered Oct 16 '22 15:10

Smail Galijasevic


It works also for verification link, but you have to use the code parameter as {##Verify email##} and not {####} in your User Pool - Message customization settings. And then also use {##Verify email##} keyword in your html template.

like image 24
komo Avatar answered Oct 16 '22 15:10

komo