Vaaljan
Vaaljan

Reputation: 832

Configure a Custom SMS Message for MFA in AWS Cognito

I Am using AWS Cognito for authentication in a web application.

If a user Forgets their password I have a Lambda Function Trigger that sends a custom email with a link that has the users email address and the verification code in so they can click the link and just enter their new password.

So There is a new requirement that should allow the user to receive an sms, but currently it looks like if you enable MFA for sending the SMS, you can only customise the message in the console area and in the Lambda function, this event.response.smsMessage does not seem to do anything.

So if the user has phone_number_verified true, it sends the sms without triggering the Lambda function.

exports.handler = function(event, context) {

if(event.triggerSource === "CustomMessage_ForgotPassword") {
    var url = 'http://myurl.com/forgotpassword/'+ event.request.userAttributes.email+'/'+event.request.codeParameter
    event.response.smsMessage = 'Password Reset: Click the link ' + url + ' or enter Verification Code: ' + event.request.codeParameter 
    event.response.emailSubject = " Password reset";
    event.response.emailMessage = "Custom HTML goes here";

}
context.done(null, event);
};

This is currently the Lambda function configure on custom message trigger in the cognito User pool.

Upvotes: 1

Views: 1954

Answers (1)

Vaaljan
Vaaljan

Reputation: 832

After a long discussion with AWS support, They came to the resolution that my SMS text was more than 140 chars. Yes 140, And then the SMS would not be sent rather the email would. No errors in logs or anything whatsoever.

So they said they will look into adding something in the logs that at least tells you that the SMS was not sent because the character limit was exceeded.

Upvotes: 1

Related Questions