1
votes

How do I define and validate URL Query String Parameters for an AWS::Serverless::Api in a SAM template?

They don't seem to be mentioned in the documentation https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html

Just to be clear this is what I am talking about enter image description here

2
Please add to your question your template yaml/json - petey

2 Answers

1
votes

I think that your response is in another resource, AWS::ApiGateway::Method.

Check the documentation (search for Request Parameters):

The request parameters that API Gateway accepts. Specify request parameters as key-value pairs (string-to-Boolean mapping), with a source as the key and a Boolean as the value. The Boolean specifies whether a parameter is required. A source must match the format method.request.location.name, where the location is querystring, path, or header, and name is a valid, unique parameter name.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-requestparameters

1
votes

The URL Query String Parameters is defined in AWS::Serverless::Function rather than AWS::Serverless::Api using RequestParameters property.

For example to define mail, name, phone as URL Query String Parameters u can do the following:

Events:
  ApiEvent:
  Type: Api
  Properties:
    Path: /path
    Method: get
    RequestParameters:
      - method.request.querystring.mail:
          Required: true
          Caching: true
      - method.request.querystring.name:
          Required: true
          Caching: true
      - method.request.querystring.phone:
          Required: false
          Caching: false

You can also define HTTP Request Headers using the following:

method.request.header.{{header_name}}
// For example: method.request.header.Authorization

I hope this helps.