我正在尝试使用 JavaScript SDK 从脚本以编程方式创建 Cognito 用户池。
我已经成功创建了用户池并通过在我的配置中指定相关 lambda 的 arn 来定义预注册和确认后触发器。(根据文档)
我的脚本如下所示:
const aws = require('aws-sdk');
const awsConfig = require('../config/config');
aws.config.update({ region: awsConfig.REGION });
const provider = new aws.CognitoIdentityServiceProvider();
// user provided args
const stage = process.argv[2];
if (!stage) {
process.stdout.write('Please provide stage as argument\n');
process.exit(1);
}
// generate arns for pre and post cognito triggers
const getArn = (lambdaName) => {
return `arn:aws:lambda:${awsConfig.REGION}:${awsConfig.AWS_ACCOUNT_ID}` +
`:function:my-project-name-${stage}-${lambdaName}`;
};
const preSignUp = getArn('preSignUp');
const postConfirmation = getArn('postConfirmation');
const userPoolConfig = {
PoolName: `mypool-${stage}`,
AutoVerifiedAttributes: ['email'],
Schema: [
{
"StringAttributeConstraints": {
"MaxLength": "2048",
"MinLength": "0"
},
"Mutable": true,
"Required": true,
"AttributeDataType": "String",
"Name": "email",
"DeveloperOnlyAttribute": false
}
],
LambdaConfig: {
PostConfirmation: postConfirmation,
PreSignUp: preSignUp
}
};
const callback = (err, resp) => {
if (err) {
process.stdout.write(`${err}\n`);
} else {
process.stdout.write(resp.UserPool.Id);
}
};
provider.createUserPool(userPoolConfig, callback);
当我运行此脚本时,它成功创建了用户池,并且当我在控制台中检查它时,触发器设置正确。
当我尝试在我的用户池中注册用户时,出现错误:
AccessDeniedException { code: 'UnexpectedLambdaException', ... }
如果我进入控制台并手动设置触发器,它就可以正常工作。
已报告此错误 - 但我没有看到任何确认,也没有解决方案:
https://github.com/aws/aws-cli/issues/2256
拼命无法修复或找到解决方法。