Pass custom attributes as placeholder in verification mail of AWS cognito

332 Views Asked by At

I have user attributes family_name and given_name I want to use this in my verification email template like

hi {given_name} {family_name} your verification code is {####}

but the placeholder is not being replaced by the value. how can I achieve that?

1

There are 1 best solutions below

0
Shree Rai On

I discover that AWS Cognito allows certain placeholders to be used in the verification emails. I created new lambda that gets triggers at Cognito custom-message-events and parses the provided parameter from Cognito and returns back as an event which fixed my issue. below is the sample code for that.

const forgot_password = async(event) => {
    let email = event.request.usernameParameter;
    let code = event.request.codeParameter;
    let username = event.request.userAttributes.username;
    event.response = {
        emailSubject: "Forgot password",
        emailMessage: "" + code + ""+username
    }
    return event
}

exports.handler = async(event) => {
    switch (event.triggerSource) {
        case "CustomMessage_ForgotPassword": 
            return forgot_password(event)
        default:
            return event

    }
};