Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito adminCreateUser from Lambda

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: '[email protected]', /* required */
        DesiredDeliveryMediums: [
            'EMAIL'
        ],
        ForceAliasCreation: false,
        MessageAction: 'SUPPRESS',
        TemporaryPassword: 'tempPassword1',
        UserAttributes: [
            {
                Name: 'email', /* required */
                Value: '[email protected]'
            },
            {
                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);
    });

};
like image 982
danielebuso Avatar asked Nov 07 '16 21:11

danielebuso


People also ask

How do you make a Cognito user from Lambda?

Access your IAM Management console and select Roles from the left menu. Click Create role and select the AWS Service Lambda role. Once both are highlighted, click Next: Permissions. Name your role whatever you want, as long as it's recognizable to you, and click Create role.

Does Cognito return JWT?

After a user logs in, an Amazon Cognito user pool returns a JWT. The JWT is a base64url-encoded JSON string ("claims") that contains information about the user. Amazon Cognito returns three tokens: the ID token, the access token, and the refresh token.

Can Cognito be an IdP?

However, a Cognito user pool is its own IdP. If an identity pool is configured correctly, it can use the app's user pools as an IdP. This way, users authenticate via user pools and are assigned IAM roles via identity pools.


1 Answers

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.

like image 159
Jeff Bailey Avatar answered Sep 18 '22 19:09

Jeff Bailey