消息AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool不是aws lambda中的函数
我正在尝试在AWS Lambda函数中使用AWS Cognito用户池。 我在教程中看到,您需要在代码中包含amazon-cognito-identity.min.js,但我不知道如何在节点js中执行此操作。 我使用npm install作为外部模块,但是我不认为aws-cognito-identity作为一个模块存在。
我安装了aws-sdk,但函数AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool在SDK中不存在。
顺便说一下,这是我在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' // your identity pool id here }); // Need to provide placeholder keys unless unauthorised user access is enabled for 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); };
这里是testingLambda函数时得到的错误消息:
{ "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)" ] }
我也有同样的问题,我刚刚发现这个令人难以置信的回购:
https://github.com/kndt84/amazon-cognito-identity-js和相关的npm包:
https://www.npmjs.com/package/amazon-cognito-identity-js-node
有用。 现在(2017年7月)的好解决scheme,等待Cognito的General Availability版本,这将在AWS中解决(有些人自2016年10月以来一直面临这个问题)。
npm install amazon-cognito-identity-js-node
和
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;
您也可以为CognitoUserAttribute
等其他项目执行相同的CognitoUserAttribute
。
请注意,你将不得不改变
const attributeEmail = new AWS.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
至:
const attributeEmail = new AWS.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail.Name, dataEmail.Value);
- 将文件从一个文件夹复制到同一个桶的s3中的另一个文件夹NODE JS
- NodeJS和Mysql。 在终止之前不会调用connection.end()会被接受吗?
- 从Lambda函数(Node)连接到MySQL数据库
- 在AWS NodeJS Lambda函数中包含来自poppler的pdftotext
- DeprecationWarning:不使用callback调用asynchronous函数已被AWS JS SDK弃用
- 如何在使用AWS SDK for Java调用AWS Lambda函数时检索context.done()消息?
- 通过HTTP确认SNS订阅时出现AuthorizationError
- 在AWS lambda函数中使用require
- 如何为托pipe在Amazon ECS上的服务器运行Node.js工作?