Javascript AWS Cognito adminCreateUser来自Lambda,使用Amplify CLI创建

Javascript AWS Cognito adminCreateUser来自Lambda,使用Amplify CLI创建,javascript,amazon-web-services,aws-lambda,amazon-cognito,aws-amplify-cli,Javascript,Amazon Web Services,Aws Lambda,Amazon Cognito,Aws Amplify Cli,我使用Amplify CLI创建了一个Lambda函数,当执行Lambda函数时,不会出现错误,但不会创建Cognito用户 我错过了什么 我已经检查了CloudWatch日志,但没有发现任何错误 我一直遵循以下文件: 我不确定等待是否有效。这个怎么样 var createUserPromise = cognitoidentityserviceprovider.adminCreateUser(params).promise(); createUserPromise.then(results =

我使用Amplify CLI创建了一个Lambda函数,当执行Lambda函数时,不会出现错误,但不会创建Cognito用户

我错过了什么

我已经检查了CloudWatch日志,但没有发现任何错误

我一直遵循以下文件:


我不确定等待是否有效。这个怎么样

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"
        });
这将起作用

测试事件

{
 "request": {
"userAttributes": {
  "custom:name": "Ajay",
  "email": "ajay@gmail.com",
  "custom:role": "Admin"
}
},
"response": {}
 }

Lambda函数

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
});
})

{
 "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
});