我正在使用 AWS SAM 在本地测试我的 Api 网关和 lambda。执行sam local start-api
和调用 lambda 时,我希望使用event
2.0版格式而不是 1 版。
我正在使用 CDKHttpApi
构造,@aws-cdk/aws-apigatewayv2
因此现在我的本地测试和部署的内容之间存在不一致。
我是 Sam config 的新手,我的template.yml文件是:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs14.x
CodeUri: .output/healthz
Timeout: 10
Events:
ApiEvent:
Type: Api
Properties:
Path: /health
Method: GET
Globals:
HttpApi:
CorsConfiguration:
AllowOrigin: "'http://localhost:3000'"
AllowMethods: "'POST, OPTIONS, GET, PUT'"
AllowHeaders: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
我已经尝试使用这些适用于 SAM 的 AWS Docs 进行各种设置(Api、HttpApi),但总是设法只获得版本 1 事件。
你能指出我做错了什么或如何指定版本吗?