在 AWS SAM 模板中将 API 事件集成配置为 "lambda" 而不是默认值 "lambda proxy"

Configure API event integration as "lambda" instead of default "lambda proxy" in AWS SAM Template

SAM 的所有示例大多在默认状态下使用 Serverless::functions 的事件。默认情况下,Lambda 的 API 集成配置为“Lambda 代理”。

我需要在“映射”中使用以下设置的集成类型“Lambda(非代理)”

如何使用 SAM 模板实现这一点?

如果您想对 API 进行更多控制(例如,绕过 AWS SAM 生成的某些 defaults/assumptions),您应该明确定义 AWS::Serverless::Api and pass along the definition of the API using the OpenAPI specification (either using the DefinitionUri or DefinitionBody attributes). In the specification, you have more control over how the API should integrate with the lambda functions. Setting the type attribute on the x-amazon-apigateway-integration object 将允许您使用aws 集成而不是 aws_proxy 集成。

您仍然应该在 lambda 函数中配置 Events 部分或手动修复必要的权限,以确保您的 API 网关将有权调用 lambda。