node.js - message AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool not a function in aws lambda -


i trying use aws cognito user pool in aws lambda function. saw in tutorial need include amazon-cognito-identity.min.js in code not sure how in node js. use npm install external modules don't think aws-cognito-identity exists yet module.

i installed aws-sdk function awscognito.cognitoidentityserviceprovider.cognitouserpool not exist in sdk.

by way, here's code in lambda:

'use strict';  var aws= require('aws-sdk');   aws.config.region = 'ap-northeast-1'; // region aws.config.credentials = new aws.cognitoidentitycredentials({     identitypoolid: 'ap-northeast-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' // identity pool id here });  // need provide placeholder keys unless unauthorised user access enabled user pool //awscognito.config.update({accesskeyid: 'anything', secretaccesskey: 'anything'})  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 error message i'm getting when testing lambda function:

{   "errormessage": "aws.cognitoidentityserviceprovider.cognitouserpool not 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)"   ] } 

i had same problem, found incredible repo:

https://github.com/kndt84/amazon-cognito-identity-js , associated npm package:

https://www.npmjs.com/package/amazon-cognito-identity-js-node

it works. solution (july 2017) while waiting general availability release of cognito fixed in aws (some people have been facing issue since october 2016).

npm install amazon-cognito-identity-js-node 

and

var aws = require('aws-sdk'); var cognitosdk = require('amazon-cognito-identity-js-node'); aws.cognitoidentityserviceprovider.authenticationdetails = cognitosdk.authenticationdetails; aws.cognitoidentityserviceprovider.cognitouserpool = cognitosdk.cognitouserpool; aws.cognitoidentityserviceprovider.cognitouser = cognitosdk.cognitouser; 

you can same other items cognitouserattribute.

note have change

const attributeemail = new aws.cognitoidentityserviceprovider.cognitouserattribute(dataemail); 

to:

const attributeemail = new aws.cognitoidentityserviceprovider.cognitouserattribute(dataemail.name, dataemail.value); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -