Cloudfront second origin 给出错误的响应

Cloudfront second origin give wrong response

我在 VPC 中有 lambda 并将网关连接到它。此外,我将网关 url 添加为云端的第二个来源,并为此来源创建具有 /api/ 路径的行为。但是当我转到 https:///api/ 时,我得到 {"message":"Not Found"} 作为响应。但是当我转到网关 url 时,我得到 Hello world 作为响应。

我的 lamda 代码是一个非常简单的“hello world”,我用它来了解 lamda 的工作原理:

exports.handler = async (event) => {
const response = {
    statusCode: 200,
    body: JSON.stringify('Hello world')
}
return response

}

我的云端配置:

有人对此有什么想法吗?

我唯一需要做的事情 - 将 /api/* 路径更改为 /api*

/api/* 的此配置会将所有请求传递到 API 网关,仍然包括请求的 /api/ 前缀。

您需要确保您的请求考虑到这一点