I defined a model with JSONschema and set it to the lambda. I could see that the model was added in Request Body like the picture below
But I also need to set Request Validator to validate it. This is my example AWS SAM template below.
Resources:
Api:
Type: "AWS::Serverless::Api"
Properties:
StageName: !Ref Environment
TracingEnabled: false
EndpointConfiguration: REGIONAL
Auth:
Authorizers:
Auth:
FunctionPayloadType: TOKEN
FunctionArn: !GetAtt Auth.Arn
Identity:
Header: authorization
Models:
RegisterCat:
$schema: "http://json-schema.org/draft-04/hyper-schema#"
title: RegisterCat
type: object
properties:
name:
type: string
maxLength: 32
species:
type: string
maxLength: 32
age:
type: integer
minimum: 0
maximum: 100
required:
- name
- species
- age
RegisterCat:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Join ["-", [example, !Ref Environment, register, cat]]
CodeUri: register_cat/
Environment:
Variables:
TABLE_NAME: !Join ["-", [!Ref Environment, cat, table]]
Policies:
- Statement:
- Sid: CatTable
Effect: Allow
Action:
- "dynamodb:PutItem"
Resource: !GetAtt CatTable.Arn
Events:
PublicApi:
Type: Api
Properties:
Path: /cat/
Method: POST
RestApiId: !Ref Api
RequestModel:
Model: RegisterCat
Required: true
I can see that there is an option to add request validator when you create method in aws cli or Cloudformation
put-method
--rest-api-id <value>
--resource-id <value>
--http-method <value>
--authorization-type <value>
[--authorizer-id <value>]
[--api-key-required | --no-api-key-required]
[--operation-name <value>]
[--request-parameters <value>]
[--request-models <value>]
[--request-validator-id <value>]
[--authorization-scopes <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: Boolean
AuthorizationScopes:
- String
AuthorizationType: String
AuthorizerId: String
HttpMethod: String
Integration:
Integration
MethodResponses:
- MethodResponse
OperationName: String
RequestModels:
Key : Value
RequestParameters:
Key : Value
RequestValidatorId: String
ResourceId: String
RestApiId: String
I read SAM specification document in Github several times and tried setting the request validator. However I couldn't find any way to set it up with SAM. Is there a way to set the request validator on method or should I request the feature in SAM repo?
Thank you for reading my question.