How do I add a (path) parameter to lambda function events using cloud formation templates?
Strangely using:
DeleteItem:
Type: Api
Properties:
Path: /item/{id}
Method: delete
Request:
Parameters:
Paths:
id: true
works using aws-sam-cli. However when I try to deploy using cloud formation it says that property Request is not defined. I got this request idea from the serverless docs but seems to only work locally. I can't find documentation on how to do this in templates so any help would be greatly appreciated.
In an AWS CloudFormation template, you can specify a Lambda function as the target of a custom resource. Use custom resources to process parameters, retrieve configuration values, or call other AWS services during stack lifecycle events. The following example invokes a function that's defined elsewhere in the template.
To automatically deploy a Lambda function, we will add information under the Resources section. Create a YAML file for your new template (this tutorial will use YAML, but CloudFormation also supports JSON format). Under the Resources section, we'll start by defining the Identity and Access Management (IAM) Role.
Yes, it is possible. Here are a few options: Manually create an SNS Topic. Add an AWS::SNS::Subscription to your stack with the lambda function as the Endpoint and the SNS topic as the TopicArn .
The Serverless Framework uses its own syntax, which is different from SAM (although can be compiled down to SAM or raw CloudFormation).
You can find the SAM specification here.
It's not explicit, but all you need to do is use the {path-name}
syntax. Adding Request
/Parameters
is not required (or supported).
For example:
Ratings:
Type: AWS::Serverless::Function
Properties:
Handler: ratings.handler
Runtime: python3.6
Events:
Api:
Type: Api
Properties:
Path: /ratings/{id}
Method: get
Would give you the an event with:
event.pathParameters.id == 'whatever-was-put-in-the-id-position'
(A long example can be found here: https://github.com/1Strategy/redirect/blob/master/redirect.yaml)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With