来自 Lambda 的 AWS Cognito adminCreateUser

我使用 Amplify CLI 创建了一个 Lambda 函数,执行 Lambda 函数时没有错误,但未创建 Cognito 用户。

我在这里缺少什么?

我已经检查了 CloudWatch Logs,但也没有发现任何错误。

/* Amplify Params - DO NOT EDIT

    AUTH_XXXXXXXXXXXXXXXXXXXX_USERPOOLID

    ENV

    REGION

Amplify Params - DO NOT EDIT */


const AWS = require('aws-sdk');

AWS.config.update({ region: process.env.AWS_REGION,accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY });


const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });


//console.log(process.env);


exports.handler = async (event) => {

    let retailerid = event.pathParameters.retailerid;


    let params = {

        UserPoolId: process.env.AUTH_XXXXXXXXXXXXXXXXXXXX_USERPOOLID, /* required */

        Username: 'testtest', /* required */

        ClientMetadata: {

        },

        DesiredDeliveryMediums: [

            'EMAIL'

        ],

        ForceAliasCreation: false,

        MessageAction: 'SUPPRESS',

        TemporaryPassword: 'mynuw000000000TTS',

        UserAttributes: [

            {

                Name: 'custom:app_role', /* required */

                Value: 'retail'

            },

            {

                Name: 'email_verified', /* required */

                Value: 'true'

            },

            {

                Name: 'email', /* required */

                Value: 'usersname@someemail.co.za'

            },

            {

                Name: 'phone_number', /* required */

                Value: '27833260000'

            },

            /* more items */

        ],

        ValidationData: [


            /* more items */

        ]

    };



开满天机
浏览 123回答 3
3回答

神不在的星期二

测试活动{ "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 eventconsole.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});};

HUX布斯

await cognitoidentityserviceprovider.adminCreateUser(params).promise()  .then((data) => {    console.log('SUCCESS', data);    })  .catch((error) => {    console.log('ERROR', error);    });这会起作用

慕哥6287543

我不确定等待是否有效。这个怎么样。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"        });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript