ppg*_*c74 1 amazon-web-services amazon-iam react-native aws-api-gateway aws-amplify
我正在尝试使用适用于 React Native 的 AWS Amplify SDK 和 API Gateway 中的 IAM 授权程序发出一个简单的获取请求。我总是收到以下错误消息:
凭证的范围应限定为有效区域,而不是“us-east-1”。
我究竟做错了什么?这是我的代码(还没有做任何事情):
function getImageIdForUpload() {
let apiName = 'MyAPIGatewayAPI';
let path = '/upload-image/get-new-id';
let myInit = {
// replace this with attributes you need
};
API.get(apiName, path, myInit).then(response => {
console.log(response)
}).catch(error => {
console.error(error.response)
});
}
Run Code Online (Sandbox Code Playgroud)
我的配置:
Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: 'eu-central-1:xxxx',
// REQUIRED - Amazon Cognito Region
region: 'eu-central-1',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'eu-central-1_xxxx',
// OPTIONAL - Amazon Cognito Web Client ID
userPoolWebClientId: 'xxxx',
},
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激 :)
自己找到了解决方案:您必须在 API 配置中设置区域。
例子:
API: {
endpoints: [
{
name: "MyAPIGatewayAPI",
endpoint: "https://xxx.execute-api.eu-central-1.amazonaws.com/dev",
region: "eu-central-1"
}
]
},
Run Code Online (Sandbox Code Playgroud)
如果 API 设置为“边缘优化”,这可能不是问题。
| 归档时间: |
|
| 查看次数: |
1666 次 |
| 最近记录: |