AWS API Gateway Request Validator
This page shows how to write Terraform and CloudFormation for API Gateway Request Validator and write them securely.
aws_api_gateway_request_validator (Terraform)
The Request Validator in API Gateway can be configured in Terraform with the resource name aws_api_gateway_request_validator
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_request_validator" "foo" {
name = "foo"
rest_api_id = aws_api_gateway_rest_api.foo.id
validate_request_body = true
validate_request_parameters = true
}
resource "aws_api_gateway_request_validator" "validator" {
name = var.request_validator_name
rest_api_id = var.rest_api_id
validate_request_body = true
validate_request_parameters = true
resource "aws_api_gateway_request_validator" "this" {
name = var.name
rest_api_id = aws_api_gateway_rest_api.this.id
validate_request_body = true
validate_request_parameters = true
}
Parameters
-
id
optional computed - string -
name
required - string -
rest_api_id
required - string -
validate_request_body
optional - bool -
validate_request_parameters
optional - bool
Explanation in Terraform Registry
Manages an API Gateway Request Validator.
Tips: Best Practices for The Other AWS API Gateway Resources
In addition to the aws_api_gateway_method_settings, AWS API Gateway has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_api_gateway_method_settings
Ensure that API Gateway stage-level cache is encrypted
It is better to enable the stage-level cache encryption which reduces the risk of data leakage.
aws_api_gateway_domain_name
Ensure to use modern TLS protocols
It is better to adopt TLS v1.2+.
aws_api_gateway_stage
Ensure to enable access logging of your API Gateway stage (v1)
It is better to enable the access logging of your API Gateway stage (v1).
aws_api_gateway_method
Ensure that your API Gateway method blocks unwanted access
It is better that the API Gateway method does not allow public access.
AWS::ApiGateway::RequestValidator (CloudFormation)
The RequestValidator in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::RequestValidator
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
Name
optional - String -
RestApiId
required - String -
ValidateRequestBody
optional - Boolean -
ValidateRequestParameters
optional - Boolean
Explanation in CloudFormation Registry
The
AWS::ApiGateway::RequestValidator
resource sets up basic validation rules for incoming requests to your API. For more information, see Enable Basic Request Validation for an API in API Gateway in the API Gateway Developer Guide.
Frequently asked questions
What is AWS API Gateway Request Validator?
AWS API Gateway Request Validator is a resource for API Gateway of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS API Gateway Request Validator?
For Terraform, the cloudskiff/driftctl, cosmic-fusion/cosmic-fusion-api and albumprinter/infra-terraform-modules source code examples are useful. See the Terraform Example section for further details.