为什么如下代码所示的AWS Cognito adminDeleteUser函数会给出“用户池不存在”错误消息?
const aws = require('aws-sdk');
aws.config.accessKeyId = 'aaaaaaa';
aws.config.secretAccessKey = 'sssssss';
aws.config.region = 'us-west-2';
const CognitoIdentityServiceProvider = new
aws.CognitoIdentityServiceProvider();
global.fetch = require('node-fetch');
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
// this section of code produces a correct userPool object
let poolData =
{
UserPoolId: 'ppppppp',
ClientId: 'ccccccc'
};
let userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
console.log('userPool: ', userPool);
// this section of code reports error: "ResourceNotFoundException:
User pool ppppppp does not exist."
let params =
{
UserPoolId: 'ppppppp',
Username: 'nnnnnnn'
};
CognitoIdentityServiceProvider.adminDeleteUser(params, (err,data) =>
{
if (err) console.log(err);
else console.log('user deleted');
});
答案 0 :(得分:1)
问题已通过更改代码自
解决aws.config.accessKeyId = 'aaaaaaa';
aws.config.secretAccessKey = 'sssssss';
aws.config.region = 'us-west-2';
到以下
aws.config.update(
{
accessKeyId: 'aaaaaaa',
secretAccessKey: 'sssssss',
region: 'us-west-2'
});
还请注意,无论是否提供有效的UserPoolId值,以下代码都会创建一个userPool对象:
let poolData =
{
UserPoolId: 'ppppppp,
ClientId: 'ccccccc'
};
let userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);