AWS CloudFormation:使用显式API作为事件源的Lambda事件
问题描述:
我试图在我的SAM模板中对我的lambda函数设置一个事件,但我希望事件源是一个明确的API端点。AWS CloudFormation:使用显式API作为事件源的Lambda事件
的文档显示了作为事件源的隐式API的事件:
GetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.get
Runtime: nodejs6.10
CodeUri: s3://bucket/api_backend.zip
Policies: AmazonDynamoDBReadOnlyAccess
Environment:
Variables:
TABLE_NAME: !Ref Table
Events:
GetResource:
Type: Api
Properties:
Path: /resource/{resourceId}
Method: get
这将是明确的API定义:
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionUri: swagger.yml
任何想法如何明确设置的事件源是MyApi?
在此先感谢。
答
我需要添加RestApiId
事件定义下,像这样:
Events:
GetResource:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /resource/{resourceId}
Method: get