AWS 自定义验证电子邮件模板

Som*_*ade 5 amazon-web-services amazon-cognito aws-lambda

我正在研究 AWS Cognito,下面是有关消息自定义的两个问题。

1) 我正在使用“链接”验证类型在 AWS Cognito 上处理“电子邮件验证消息”。我遇到了“电子邮件消息”使其动态化的问题。

2)如何根据用户组或有条件发送不同的“邮件消息”内容?

请建议。

谢谢

Har*_*ips 3

这对我有用。因此,如果有人知道更好的答案,请指出我。选择“链接”选项发送链接对我来说不起作用。所以我尝试在正文中手动添加链接,选择“代码”选项。但正如 @SomnathRokade 和 @snehanshu.js 所建议的那样,这在一开始并不起作用。

这是我的 lambda 函数。

exports.handler = async (event, context) => {
var welcomeMessage = `
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<p>Dear ${event.userName},</p>

<p>Anything</p>

<p>Any text before the link <a href="http://localhost:3000/changePassword?username=${event.userName}">here.</a> Your username is your Network Rail email address. Your temporary password is ${event.request.codeParameter}.</p>

<p>Any text</p>

<p>Any other text</p>

<p>Many Thanks </p>
</body>
</html>
`;

if (event.triggerSource === "CustomMessage_AdminCreateUser") {
event.response.emailSubject = "CAT Welcome Email";
event.response.emailMessage = welcomeMessage;
}
return context.done(null,event);
};
Run Code Online (Sandbox Code Playgroud)

这不起作用。

我用谷歌搜索并发现不同的地方提到“event.request.userName”,“event.request.userAttributes.sub”等而不是“event.userName”。但他们也没有工作。

然后我尝试在 lambda 控制台日志中打印事件对象。我发现上述所有字段的值都是相同的。有趣的是,对象中没有“event.request.userName”字段。相反,有“event.request.usernameParameter”。不过,该值与“event.userName”相同。不管怎样,我尝试添加“event.request.usernameParameter”,令人惊讶的是它有效。

毕竟,我发现这个文档解释了它。

因此,底线是使用“Code”选项,在电子邮件正文中包含“event.request.usernameParameter”和“event.request.codeParameter”。有效。

希望我帮助了某人。