要在AWS Cognito用户注册时发送验证短信或电子邮件,您可以使用AWS SDK和AWS Cognito提供的功能。
以下是使用AWS SDK for JavaScript(Node.js)的示例代码:
const AWS = require('aws-sdk');
AWS.config.update({ region: 'your_region' });
const cognito = new AWS.CognitoIdentityServiceProvider();
const params = {
ClientId: 'your_client_id',
Username: 'user_email',
Password: 'user_password',
UserAttributes: [
{
Name: 'email',
Value: 'user_email'
},
// Add other user attributes if needed
],
ValidationData: []
};
cognito.signUp(params, (err, data) => {
if (err) {
console.log('Error:', err);
} else {
console.log('Success:', data);
}
});
请确保将以下值替换为您的实际值:
此代码将使用AWS SDK进行用户注册并发送验证电子邮件。您可以通过在UserAttributes数组中添加其他用户属性来提供其他用户信息。
如果您希望发送验证短信而不是电子邮件,您需要使用AWS SNS(Simple Notification Service)来完成。您可以在用户注册后使用AWS Lambda触发器在AWS Cognito中的“用户注册”事件上运行AWS Lambda函数,该函数使用SNS发送验证短信。
希望这可以帮助到您!