AWS API Gateway Gateway Response
This page shows how to write Terraform and CloudFormation for API Gateway Gateway Response and write them securely.
aws_api_gateway_gateway_response (Terraform)
The Gateway Response in API Gateway can be configured in Terraform with the resource name aws_api_gateway_gateway_response
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_gateway_response" "response_4xx" {
rest_api_id = var.api
status_code = "500"
response_type = "DEFAULT_4XX"
response_templates = {
"application/json" = "{\"message\":$context.error.messageString}"
resource "aws_api_gateway_gateway_response" "unauthorized" {
rest_api_id = aws_api_gateway_rest_api.default.id
response_type = "UNAUTHORIZED"
status_code = "401"
response_templates = {
resource "aws_api_gateway_gateway_response" "unauthorized" {
rest_api_id = aws_api_gateway_rest_api.api_gateway.id
response_type = "UNAUTHORIZED"
status_code = "401"
response_templates = {
Parameters
-
id
optional computed - string -
response_parameters
optional - map from string to string -
response_templates
optional - map from string to string -
response_type
required - string -
rest_api_id
required - string -
status_code
optional - string
Explanation in Terraform Registry
Provides an API Gateway Gateway Response for a REST API Gateway.
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::GatewayResponse (CloudFormation)
The GatewayResponse in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::GatewayResponse
. 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
-
RestApiId
required - String -
ResponseType
required - String -
StatusCode
optional - String -
ResponseParameters
optional - Map -
ResponseTemplates
optional - Map
Explanation in CloudFormation Registry
The
AWS::ApiGateway::GatewayResponse
resource creates a gateway response for your API. For more information, see API Gateway Responses in the API Gateway Developer Guide.
Frequently asked questions
What is AWS API Gateway Gateway Response?
AWS API Gateway Gateway Response 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 Gateway Response?
For Terraform, the vistaprint/TerraformModules, Ryxias/go-chuuni and airbnb/rudolph source code examples are useful. See the Terraform Example section for further details.