gpt4 book ai didi

amazon-web-services - AWSCognito 配置错误中缺少区域

转载 作者:行者123 更新时间:2023-12-01 10:38:23 25 4
gpt4 key购买 nike

我正在使用 aws-sdk javascript在我的后端,我可以使用 AWS很好,但是当我尝试使用 getOpenIdTokenForDeveloperIdentity 时方法我得到一个 "Missing region in config error"作为回应。

var config = new AWS.Config({
accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETYKEY", region: 'us-east-1'
});

var params = {
IdentityPoolId: 'MYIDENTITYPOOLID', /* required */
Logins: { /* required */
"login.my.myapp": 'string',
/* anotherKey: ... */
},
IdentityId: null,
TokenDuration: 0
};

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

在文档中它说:

By default, credentials and region settings are left unconfigured. This should be configured by the application before using any AWS service APIs.



所以我设置了我的区域,但为什么我仍然收到错误消息?

最佳答案

您正在本地设置区域 config多变的。它应该设置在全局AWS.config , 像这样:

AWS.config.region = 'us-east-1';

这同样适用于凭证。如果您想为所有 AWS 客户端使用 Amazon Cognito 凭证,您应该初始化 AWS.config.credentials像这样:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'YOUR_POOL_ID'
});

我希望这有帮助!

关于amazon-web-services - AWSCognito 配置错误中缺少区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31976202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com