I'm having trouble on specifying requred query string params within the template.yml file of a SAM project. So far I had no luck on finding a such method and only found that we can access the query string params within a lambda functoin via the event.queryStringParameters header.
So should I check if a parameter is required or not at the lambda layer? Or is there a way to do this at the API layer itself. Because I know that in serverless framework we can specify if a query string param is required or not as below:
functions:
create:
handler: posts.create
events:
- http:
path: posts
method: get
request:
parameters:
querystrings:
type: true
please find a snippet of a template.yaml below that works for me. Ofc you need to replace the placeholders.
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: <path/to/your/lambda>
Role: <arn of lambda role>
Events:
MyGetEvent:
Type: Api
Properties:
Path: <my/api/path>
Method: get
RestApiId:
Ref: MyApi
RequestParameters:
- method.request.querystring.myqueryparam:
Required: true
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