I am using Cognito's Custom message Lambda trigger to send a dynamic message before validation.I want to get tempPassword and applicationUrl values from ClientMetadata and encrypt them. As this document shows, clientMetadata is one of the Custom message request parameters. However, while the other parameters specified here are coming to the input of the Lambda, the clientMetadata parameter does not. Did I do something wrong somewhere?
The ClientMetadata is intended for you to pass custom data to the "Custom message" lambda function through an API operation, as per the documentation. If you don't pass any custom data, the field won't be present in the lambda input.
The following API operations allow passing the ClientMetadata:
Usage example, calling SignUp operation with ClientMetadata:
var params = {
ClientId: '3n4b5urk1ft4fl3mg5e62d9ado'
Password: 'PASSWORD'
Username: 'jane@example.com'
ClientMetadata: {
'tempPassword': 'PASSWORD',
'applicationUrl': 'example.com'
},
UserAttributes: [
{
Name: 'email',
Value: 'jane@example.com'
},
{
Name: 'name',
Value: 'Jane'
}
]
};
cognitoidentityserviceprovider.signUp(params, (err, data) => {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
And then the lambda will receive such data within the CustomMessage_SignUp
triggerSource:
exports.handler = async (event) => {
// CustomMessage_SignUp : Custom message – To send the confirmation code post sign-up.
if (event.triggerSource === 'CustomMessage_SignUp') {
let tempPassword = event.request.clientMetadata.tempPassword; // 'PASSWORD'
let applicationUrl = event.request.clientMetadata.applicationUrl; // 'example.com'
...
}
}