AWS API Gateway Integration Response
This page shows how to write Terraform and CloudFormation for API Gateway Integration Response and write them securely.
aws_api_gateway_integration_response (Terraform)
The Integration Response in API Gateway can be configured in Terraform with the resource name aws_api_gateway_integration_response
. The following sections describe 1 example of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_api_gateway_integration_response" "tfer--0abe4bmm65-002F-59easd-002F-OPTIONS-002F-200" {
http_method = "OPTIONS"
resource_id = "59easd"
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
Parameters
-
content_handling
optional - string -
http_method
required - string -
id
optional computed - string -
resource_id
required - string -
response_parameters
optional - map from string to string -
response_templates
optional - map from string to string -
rest_api_id
required - string -
selection_pattern
optional - string -
status_code
required - string
Explanation in Terraform Registry
Provides an HTTP Method Integration Response for an API Gateway Resource. -> Note: Depends on having
aws_api_gateway_integration
inside your rest api. To ensure this you might need to add an explicitdepends_on
for clean runs.
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::Method IntegrationResponse (CloudFormation)
The Method IntegrationResponse in ApiGateway can be configured in CloudFormation with the resource name AWS::ApiGateway::Method IntegrationResponse
. 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
ContentHandling
Specifies how to handle request payload content type conversions. Valid values are:
CONVERT_TO_BINARY
: Converts a request payload from a base64-encoded string to a binary blob.CONVERT_TO_TEXT
: Converts a request payload from a binary blob to a base64-encoded string. If this property isn't defined, the request payload is passed through from the method request to the integration request without modification.
Required: No
Type: String
Update requires: No interruption
ResponseParameters
The response parameters from the backend response that API Gateway sends to the method response. Specify response parameters as key-value pairs (string-to-string mappings).
Use the destination as the key and the source as the value:
- The destination must be an existing response parameter in the MethodResponse property.
- The source must be an existing method request parameter or a static value. You must enclose static values in single quotation marks and pre-encode these values based on the destination specified in the request.
For more information about templates, see API Gateway Mapping Template and Access Logging Variable Reference in the API Gateway Developer Guide.
Required: No
Type: Map of String
Update requires: No interruption
ResponseTemplates
The templates that are used to transform the integration response body. Specify templates as key-value pairs (string-to-string mappings), with a content type as the key and a template as the value. For more information, see API Gateway Mapping Template and Access Logging Variable Reference in the API Gateway Developer Guide.
Required: No
Type: Map of String
Update requires: No interruption
SelectionPattern
A regular expression that specifies which error strings or status codes from the backend map to the integration response.
Required: No
Type: String
Update requires: No interruption
StatusCode
The status code that API Gateway uses to map the integration response to a MethodResponse status code.
Required: Yes
Type: String
Update requires: No interruption
Explanation in CloudFormation Registry
IntegrationResponse
is a property of the Amazon API Gateway Method Integration property type that specifies the response that API Gateway sends after a method's backend finishes processing a request.
Frequently asked questions
What is AWS API Gateway Integration Response?
AWS API Gateway Integration 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 Integration Response?
For Terraform, the denniswed/headsincloud-FO-copy source code example is useful. See the Terraform Example section for further details.