getCredentialsForIdentity - ResourceNotFoundException

时间:2018-06-05 22:25:13

标签: javascript amazon-web-services amazon-cognito

我正在尝试创建一个认知身份池,为其分配角色&从创建的标识池中获取凭据。但由于某种原因,它无法找到错误创建的标识池资源 - " {ResourceNotFoundException:Identity' us-east-2:9b1d5236-c8e1-40f5-ab44-9968101c3fde&# 39;找不到。 "。我附上了代码示例&我无法弄清楚我做错了什么。我环顾四周没有成功。 感谢。

var AWS = require('aws-sdk');
var cognitoidentity = new AWS.CognitoIdentity({apiVersion: '2014-06-30'});

exports.handler = (event, context, callback) => {
    // TODO implement
    var params = {
        AllowUnauthenticatedIdentities: false, /* required */
        IdentityPoolName: 'admin_pool', /* required */
        CognitoIdentityProviders: [
            {
            ClientId: '6m1sp69cptu5e5j7ve3arknkjgm',
            ProviderName: 'cognito-idp.us-east-2.amazonaws.com/us-east-2_OAAtfnU3c3',
            ServerSideTokenCheck: false
            }
        ]
    };

    cognitoidentity.createIdentityPool(params, function(err, data) {
        if (err)
            console.log(err, err.stack); // an error occurred
        else {
            var idpid = data.IdentityPoolId;
            console.log(data);           // successful response
            let params = {
                IdentityPoolId: data.IdentityPoolId, /* required */
                Roles: { /* required */
                    'authenticated': 'arn:aws:iam::xxxxxxxxxx:role/cc_admin',
                    'unauthenticated': 'arn:aws:iam::xxxxxxxxxx:role/Cognito_admin_poolUnauth_Role'
                }
            };

            cognitoidentity.setIdentityPoolRoles(params, function(err, data) {
                if (err) console.log(err, err.stack); // an error occurred
                else {
                    console.log('retval:' + JSON.stringify(data));           // successful response

                    var params = {
                        IdentityId: idpid
                    };

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

0 个答案:

没有答案
相关问题