Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SAM required query string parameters

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
like image 458
Ashan Priyadarshana Avatar asked Apr 16 '26 06:04

Ashan Priyadarshana


1 Answers

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
like image 89
Ihor Shylo Avatar answered Apr 19 '26 15:04

Ihor Shylo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!