配置错误中的AWSCognito缺少区域 [英] AWSCognito Missing region in config error
问题描述
我在后端使用了 aws-sdk javascript
,可以使用 AWS
罚款,但当我尝试使用 getOpenIdTokenTokenForDeveloperIdentity
方法时,得到一个配置错误中缺少区域
作为响应。
I'm using the aws-sdk javascript
in my back-end and I can use AWS
fine but when I try to use the getOpenIdTokenForDeveloperIdentity
method I get a "Missing region in config error"
as a response.
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
});
在文档中说:
默认情况下,凭据和区域设置未配置。应该在使用任何AWS服务API之前由应用程序配置。
By default, credentials and region settings are left unconfigured. This should be configured by the application before using any AWS service APIs.
所以我设置了我的区域,但是为什么仍然出现错误? ?
So I set my region but why am I still getting an error?
推荐答案
您正在使用本地 config
变量设置区域。应该在全局 AWS.config
中进行设置,如下所示:
You are setting the region in a local config
variable. It should be set in the global AWS.config
, like this:
AWS.config.region = 'us-east-1';
凭据同样如此。如果您想对所有AWS客户端使用Amazon Cognito凭证,则应像这样初始化 AWS.config.credentials
:
The same applies for the credentials. In case you want to use Amazon Cognito Credentials for all your AWS clients, you should initialize AWS.config.credentials
like this:
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'YOUR_POOL_ID'
});
我希望这会有所帮助!
这篇关于配置错误中的AWSCognito缺少区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!