Zac*_*scs 5 amazon-web-services aws-cloudformation aws-lambda
如何使用云形成模板向lambda函数事件添加(路径)参数?
奇怪地使用:
DeleteItem:
Type: Api
Properties:
Path: /item/{id}
Method: delete
Request:
Parameters:
Paths:
id: true
Run Code Online (Sandbox Code Playgroud)
使用aws-sam-cli工作。但是,当我尝试使用云形成进行部署时,它说未定义属性Request。我从无服务器文档中得到了这个请求的想法,但似乎只能在本地工作。我在模板中找不到有关如何执行此操作的文档,因此将不胜感激任何帮助。
无服务器框架使用其自己的语法,该语法与SAM不同(尽管可以编译为SAM或原始CloudFormation)。
您可以在此处找到SAM规范。
它不是明确的,但是您需要做的就是使用{path-name}语法。不需要(或不支持)添加Request/ Parameters。
例如:
Ratings:
Type: AWS::Serverless::Function
Properties:
Handler: ratings.handler
Runtime: python3.6
Events:
Api:
Type: Api
Properties:
Path: /ratings/{id}
Method: get
Run Code Online (Sandbox Code Playgroud)
会给您一个事件:
event.pathParameters.id == 'whatever-was-put-in-the-id-position'
(可以在这里找到一个很长的示例:https : //github.com/1Strategy/redirect/blob/master/redirect.yaml)
| 归档时间: |
|
| 查看次数: |
2431 次 |
| 最近记录: |