我正在使用 NodeJS 制作一个后触发 lambda 函数,以将新注册的用户移动到特定池:
const AWS = require('aws-sdk');
const cognito = new AWS.CognitoIdentityServiceProvider();
export const hello = (event, context, callback) => {
console.log(event);
const params = {
GroupName: 'ADMIN',
Username: event.userName,
UserPoolId: event.userPoolId,
};
cognito.adminAddUserToGroup(params, (err, data) => {
if (err) {
callback(err)
}
callback(null, event);
});
};
我serverless.yml
添加了 iamRoleStatements,因此该函数具有正确的权限(我认为):
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- cognito-sync:*
- cognito-identity:*
Resource: arn:aws:cognito-identity:*:*:*
- Effect: Allow
Action:
- cognito-idp:*
Resource: arn:aws:cognito-idp:*:*:*
目前我的错误是:
An error occurred (InvalidLambdaResponseException) when calling the AdminConfirmSignUp operation: Invalid lambda function output : Invalid JSON
更新:
它莫名其妙地开始使用相同的代码。去搞清楚。