[Feature Request] Schema validation on an API Gateway Request
See original GitHub issueI defined a schema to validate API request. It works fine in API Gateway but sam local doesn’t execute the request validation. The lambda function is then executed with incorrect payload.
RestApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowOrigin: "'*'"
AllowHeaders:
"'Content-Type'"
DefinitionBody:
swagger: "2.0"
info:
title:
Ref: AWS::StackName
x-amazon-apigateway-request-validators:
all:
validateRequestBody: true
validateRequestParameters: true
paths:
"/object":
post:
x-amazon-apigateway-request-validator: all
parameters:
- in: body
name: Object
required: true
schema:
type: object
properties:
title:
type: string
minLength: 10
maxLength: 200
description:
type: string
minLength: 10
maxLength: 600
required:
- title
- description
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Post.Arn}/invocations
responses: {}
Is it the normal behavior ? Will it be implemented ?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:23
- Comments:20 (4 by maintainers)
Top Results From Across the Web
Enable request validation in API Gateway - AWS Documentation
Learn how to enable request validation on methods for API Gateway. You can validate a request body by specifying a model schema or...
Read more >REST API Gateway - Request body validation - YouTube
In this video we will learn about request body validation using Amazon API Gateways. Let's say that you have a backend that doesn't...
Read more >Using JSON Schema Validation with the AWS API Gateway
If you want to accept JSON payloads from POST requests that contain data created by your frontend client you may end up needing...
Read more >How to Validate Requests to the AWS API Gateway using CDK
API Gateway can perform the basic validation. When the validation fails, API Gateway immediately fails the request, returns a 400 error response ...
Read more >Validate API Specification - Software AG Documentation
The API requests that fail the specification validation are considered as policy violations. Such policy violation events that are generated can be viewed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
SAM CLI does not do any schema validation on the request like API Gateway does. Marking this as a feature request and will update the title to reflect the request.
@praneetap
It’s curious that this is advertised heavily in the AWS documentation and by TAMs and solution architects as a solution to test and develop serverless applications yet there aren’t enough resources for the project.
In the past, there have been other things of this nature that have completely deterred us from using serverless and SAM specifically. It doesn’t feel great to hear, as an AWS customer, that a technology so front and center doesn’t have enough resources dedicated to it.
I don’t think idea number 1 is an acceptable solution because it is important to be able to emulate this feature locally for development and testing. It also helps to “sell” this technology to developers who are averse to using serverless because of this problem of not being able to troubleshoot and emulate things locally. As an AWS advocate at my company, this has been a main failure point to convince teams to leverage the technology.
I think I could live with the second suggestion, but it doesn’t feel super great either.
Looking forward to see movement on this issue in the future.