AWS API Gateway Method Response

This page shows how to write Terraform and CloudFormation for API Gateway Method Response and write them securely.

aws_api_gateway_method_response (Terraform)

The Method Response in API Gateway can be configured in Terraform with the resource name aws_api_gateway_method_response. The following sections describe 1 example of how to use the resource and its parameters.

Example Usage from GitHub

api_gateway_method_response.tf#L1
resource "aws_api_gateway_method_response" "tfer--0abe4bmm65-002F-59easd-002F-OPTIONS-002F-200" {
  http_method = "OPTIONS"
  resource_id = "59easd"

  response_models = {
    "application/json" = "Empty"

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an HTTP Method Response for an API Gateway Resource.

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.

risk-label

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.

risk-label

aws_api_gateway_domain_name

Ensure to use modern TLS protocols

It is better to adopt TLS v1.2+.

risk-label

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).

risk-label

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.

Review your AWS API Gateway settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::ApiGateway::Method MethodResponse (CloudFormation)

The Method MethodResponse in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::Method MethodResponse. 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

ResponseModels The resources used for the response's content type. Specify response models as key-value pairs (string-to-string maps), with a content type as the key and a Model resource name as the value.
Required: No
Type: Map of String
Update requires: No interruption

ResponseParameters Response parameters that API Gateway sends to the client that called a method. Specify response parameters as key-value pairs (string-to-Boolean maps), with a destination as the key and a Boolean as the value. Specify the destination using the following pattern: method.response.header.name, where name is a valid, unique header name. The Boolean specifies whether a parameter is required.
Required: No
Type: Map of Boolean
Update requires: No interruption

StatusCode The method response's status code, which you map to an IntegrationResponse.
Required: Yes
Type: String
Update requires: No interruption

Explanation in CloudFormation Registry

MethodResponse is a property of the AWS::ApiGateway::Method resource that defines the responses that can be sent to the client that calls a method.

Frequently asked questions

What is AWS API Gateway Method Response?

AWS API Gateway Method 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 Method Response?

For Terraform, the denniswed/headsincloud-FO-copy source code example is useful. See the Terraform Example section for further details.