【发布时间】:2022-01-30 23:59:45
【问题描述】:
我有以下 serverless.yaml:
getSth:
handler: src/handlers/getSth.getSth
events:
- http:
path: getSth
method: get
cors: true
private: true
authorizer: authorizerFunc
authorizerFunc:
handler: src/handlers/authorizer.authorizer
getSth 处理程序:
module.exports.getSth = async (event, context) => {
const response = {
statusCode: 200,
body: JSON.stringify({message: "nice you can call this});
}
return response;
}
authorizerFunc:
module.exports.authorizer = async (event, context) => {
console.log('i will fail your authorization');
let response = {
isAuthorized: false,
context: {
stringKey: "value",
numberKey: 1,
booleanKey: true,
arrayKey: ["value1", "value2"],
mapKey: { value1: "value2" },
},
};
return response;
}
尽管授权方不应允许执行该 getSth 函数,但仍会导致响应 200。控制台日志“我将无法通过您的授权”也未记录。
我做错了什么?
【问题讨论】:
-
您好,您可以共享
getSth和authorizerFunc的CloudWatch 日志吗? -
从您的
yaml看来,您正在部署一个 REST Api(即 API Gateway V1),但这种形式的授权函数适用于 HTTP Api(即 API Gateway V2)。对于 REST API,您的授权方 lambda 必须返回 IAM 策略。请参阅docs.aws.amazon.com/apigateway/latest/developerguide/… 与 aws.amazon.com/de/blogs/compute/… -
您是否在 AWS 控制台中检查了授权方实际上已附加到您的函数?
标签: amazon-web-services aws-lambda serverless aws-serverless