因此,我试图在API Gateway中设置自定义授权者。
我可以得到它,以将具有有效令牌的请求转发到API方法中指定的lambda函数。我无法弄清楚如何访问授权者传递的principalId。
执行请求时,我会在Cloud监视日志中获得以下内容:
Authorizer result body before parsing:
{
"principalId": "16",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Condition": {},
"Action": "execute-api:Invoke",
"Resource": [
"arn:aws:execute-api:eu-central-1:****:***/null/*/*"
],
"Effect": "Allow"
},
{
"Condition": {},
"Action": "execute-api:Invoke",
"Resource": [],
"Effect": "Deny"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
那么,如何在lambda函数中访问principalId?该对象是否甚至传递给了lambda?如果不是,那么至少如何传递principalId?
我正在尝试使用适用于 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: …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-iam react-native aws-api-gateway aws-amplify