AWS通过JS从aws cognitio获取所有用户

时间:2017-08-03 11:38:37

标签: amazon-web-services aws-sdk aws-cognito

如何从aws cognito中获取所有用户?

我发现了这个:列出用户 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#listUsers-property

    var cognito = new AWSCognito.CognitoIdentityServiceProvider;

    cognito.listUsers(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
    });

但是当我这样做时,我得到了这个错误:

没有任何定义......

也尝试了这个:

  AWS.config.region = 'eu-central-1'; // Region
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: 'eu-central-1:',
        Logins: {
            'cognito-idp.eu-central-1.amazonaws.com/eu-central-1_': result.getIdToken().getJwtToken()
        }
    });

这里我的结果没有定义......

如何获取所有用户?

1 个答案:

答案 0 :(得分:0)

这是一个有效的例子:

let params = {
        UserPoolId: '<<PoolID>>',
        AttributesToGet: [
            'email',
            'family_name',
            'given_name',
            'custom:client',
            'phone_number'
        ],
        Limit: 0,
    };
    this.awsSDKAuth().listUsers(params, (err, data) => {
        if (err) console.log(err, err.stack); // an error occurred
        else {
            console.log(data.Users);
        }
    });