3 回答
TA贡献1963条经验 获得超6个赞
测试活动
{
"request": {
"userAttributes": {
"custom:name": "Ajay",
"email": "ajay@gmail.com",
"custom:role": "Admin"
}
},
"response": {}
}
拉姆达函数
var AWS = require('aws-sdk');
var resp200ok = { statusCode: 200, headers: {'Content-Type': 'application/json'}, body: {} };
var cognitoidentityserviceprovider = new
AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
exports.handler = function(event, context, callback){
const attributes = event.request.userAttributes; // read user attributes from event
console.log('User Role : ',attributes['custom:role'])
var params = {
UserPoolId:'*********',
Username: attributes.email,
//TemporaryPassword: 'Password!1',
DesiredDeliveryMediums: ["EMAIL"],
UserAttributes: [
{
Name: "email",
Value: attributes.email
},
{
Name: 'email_verified', /* required */
Value: 'true'
},
{
Name: 'custom:name', /* required */
Value: attributes['custom:name']
},
{
Name: 'custom:role', /* required */
Value: attributes['custom:role']
},
],
};
cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log('SUCCESS', data); // successful response
});
};
TA贡献1876条经验 获得超6个赞
await cognitoidentityserviceprovider.adminCreateUser(params).promise()
.then((data) => {
console.log('SUCCESS', data);
})
.catch((error) => {
console.log('ERROR', error);
});
这会起作用
TA贡献1831条经验 获得超10个赞
我不确定等待是否有效。这个怎么样。
var createUserPromise = cognitoidentityserviceprovider.adminCreateUser(params).promise();
createUserPromise.then(results => {
// TODO implement
const response = {
statusCode: 200,
// Uncomment below to enable CORS requests
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify(retailerid),
};
return response;
})
.catch(err => {
console.log("Error: ", err);
return "err"
});
添加回答
举报