I am trying to use the AWS Cognito custom pool in my AWS Lambda function. I saw in the tutorial that you will need to include amazon-cognito-identity.min.js in your code, but I'm not sure how to do this in node js. I use the npm installation for external modules, but I do not think that aws-cognito-identity still exists as a module.
I installed aws-sdk, but the AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool function does not exist in the SDK.
By the way, here is my code in Lambda:
'use strict';
var AWS= require('aws-sdk');
AWS.config.region = 'ap-northeast-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'ap-northeast-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});
var poolData = {
UserPoolId : 'us-east-1_xxxxxxxxx',
ClientId : 'xxxxxxxxxxxxxxxxxxxxxxxxx'
};
var userPool = new AWS.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
module.exports.handler = function(event, context, cb) {
var attributeList = [];
var email = event.email;
var username=event.username;
var password = event.password;
var dataEmail = {
Name : 'email',
Value : email
};
var dataPhoneNumber = {
Name : 'phone_number',
Value : '+15555555555'
};
var attributeEmail = new AWS.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
var attributePhoneNumber = new AWS.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);
attributeList.push(attributeEmail);
attributeList.push(attributePhoneNumber);
userPool.signUp(username, password, attributeList, null, function(err, result){
if (err) {
alert(err);
return;
}
username = result.user;
}
); return cb(null, username);
};
and here is the error message that I get when testing the lambda function:
{
"errorMessage": "AWS.CognitoIdentityServiceProvider.CognitoUserPool is not a function",
"errorType": "TypeError",
"stackTrace": [
"Module._compile (module.js:409:26)",
"Object.Module._extensions..js (module.js:416:10)",
"Module.load (module.js:343:32)",
"Function.Module._load (module.js:300:12)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}
leo c source
share