Checking Request Path Parameter for AWS API Gateway?

Say I have an api with paths /and /{pets}and /{pets}/pet. Now I'm trying to check the path {pets}, so that only a path having 6 alphanumeric characters will be checked and processed for the backend lambda, all others will be rejected. I tried the following scheme, which determines the format and type of the parameter. I even tried to use the template in the circuit, but it does not seem to work. May I learn how to restrict only path parameters to specific identifiers.

{
  ......
  "/{pets}/pet": {
      "get": {
          "consumes": [
              "application/json"
          ],
          "produces": [
              "application/json"
          ],
          "parameters": [{
              "name": "pets",
              "in": "path",
              "required": true,
              "schema": {
                  "type": "string",
                  "pattern": "[A-Za-z0-9]{6}"
              }
          }],
          "responses": {
              "200": {
                  "description": "200 response",
                  "schema": {
                      "$ref": "#/definitions/Empty"
                  }
              }
          },
          "x-amazon-apigateway-request-validator": "Validate query string parameters and headers",
          "x-amazon-apigateway-integration": {
              "responses": {
                  "default": {
                      "statusCode": "200"
                  }
              },
              "requestTemplates": {
                  "application/json": "##  See ...."
              },
              "uri": "........",
              "passthroughBehavior": "when_no_templates",
              "httpMethod": "POST",
              "contentHandling": "CONVERT_TO_TEXT",
              "type": "aws"
          }
      }
  }
  .....
}

What I'm trying to achieve:

https://api.example.com/aacc77/pet -- Accept
https://api.example.com/aacc77s/pet -- Reject
https://api.example.com/aacc7/pet -- Reject
https://api.example.com/aacc_7/pet -- Reject

Basically, I want to use this regex pattern for the path [A-Za-z0-9] {6} .

"pets": {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Pets Schema",
  "type": "string",
  "pattern": "[A-Za-z0-9]{6}"
}

I see that there is a related question, I wonder if there is a solution for this.

+4

Source: https://habr.com/ru/post/1688987/


All Articles