Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you call adminInitiateAuth from NodeJS Lambda?

I am trying to call adminInitiateAuth as follows:

var params = {
        AuthFlow: 'ADMIN_NO_SRP_AUTH',
        ClientId: 'xxxxxxxxx',
        UserPoolId: 'eu-west-1_xxxxxx',
        AuthParameters: {
            email: email,
            password: password
        }
    };

    var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
    cognitoidentityserviceprovider.adminInitiateAuth(params, function(err, data) {
      if (err) {
            console.log(err, err.stack);
        } else {
            console.log(data);
        }
    });

But I am getting the following error:

TypeError: cognitoidentityserviceprovider.adminInitiateAuth is not a function

Any ideas what I am doing wrong here? Other functions such as signUp work when called in the same manner!

like image 638
RossP Avatar asked Jul 31 '16 17:07

RossP


People also ask

Can I use Axios in Lambda?

AWS Lambda setup: create layer to interact with webhooks - Snyk User Docs. The example code for Create Lambda function to connect Snyk to Slack uses axios to interact with the Slack webhooks. Therefore you must add a layer to the new AWS Lambda function to be able to use axios.

How do I use AWS SDK in Lambda node?

To integrate the latest version of an AWS SDK into your Lambda function's deployment package, create a Lambda layer, and then add it to your function. You can use either the AWS Command Line Interface (AWS CLI) or the Lambda console to create a Lambda layer and add it to your function.

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.

Can One Lambda have multiple handlers?

Best practices suggest that one separate the handler from the Lambda's core logic. Not only is it okay to add additional definitions, it can lead to more legible code and reduce waste--e.g. multiple API calls to S3.


1 Answers

I've been looking into this as well and it appears that the NodeJS AWS sdk that is being provided for the Lambda functions is version 2.4.9, you can check by running:

console.log('SDK Version is ' + AWS.VERSION)

The version that was released with adminInitiateAuth is version 2.4.11. I assume that Amazon will update their lambda machines soon but in the meantime you could try adding adding the new sdk manually by

npm install aws-sdk

and then zipping up your lambda file with the node_modules folder.

like image 135
smuff Avatar answered Sep 19 '22 10:09

smuff