AWS Cognito adminCreateUser from Lambda

筅森魡賤 提交于 2020-01-13 10:13:43

问题


I'm trying to create a user in a AWS User Pool from an AWS Lambda

I tried with this script took from what seems to be the official JavascriptSDK for the AWS but can't get it working. http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#adminCreateUser-property

I keep getting this error:

TypeError: cognitoidentityserviceprovider.adminCreateUser is not a function

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

exports.handler = (event, context, callback) => {

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

    var params = {
        UserPoolId: 'eu-west-1_XXXXXXXX', /* required */
        Username: 'me@example.com', /* required */
        DesiredDeliveryMediums: [
            'EMAIL'
        ],
        ForceAliasCreation: false,
        MessageAction: 'SUPPRESS',
        TemporaryPassword: 'tempPassword1',
        UserAttributes: [
            {
                Name: 'email', /* required */
                Value: 'me@example.com'
            },
            {
                Name: 'name', /* required */
                Value: 'Me'
            },
            {
                Name: 'last_name', /* required */
                Value: 'lastme'
            }
            /* more items */
        ]
    };
    cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
        callback(null, data);
    });

};

回答1:


Sorry for the issues. You're getting this error because Lambda isn't currently running their execution environment with the most recent JS SDK. Until that is updated, you should be able to work around this by manually pulling in the most recent version.



来源:https://stackoverflow.com/questions/40475380/aws-cognito-admincreateuser-from-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!