Provides an HTTP Method Integration Response for an API Gateway Resource.
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "MyDemoResource" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
path_part = "mydemoresource"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "MOCK"
}
resource "aws_api_gateway_method_response" "response_200" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
status_code = "200"
}
resource "aws_api_gateway_integration_response" "MyDemoIntegrationResponse" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_resource.MyDemoResource.id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
status_code = aws_api_gateway_method_response.response_200.status_code
# Transforms the backend JSON response to XML
response_templates = {
"application/xml" = <<EOF
#set($inputRoot = $input.path('$'))
<?xml version="1.0" encoding="UTF-8"?>
<message>
$inputRoot.body
</message>
EOF
}
}
The following arguments are required:
http_method
- (Required) HTTP method (GET
, POST
, PUT
, DELETE
, HEAD
, OPTIONS
, ANY
).resource_id
- (Required) API resource ID.rest_api_id
- (Required) ID of the associated REST API.status_code
- (Required) HTTP status code.The following arguments are optional:
content_handling
- (Optional) How to handle request payload content type conversions. Supported values are CONVERT_TO_BINARY
and CONVERT_TO_TEXT
. If this property is not defined, the response payload will be passed through from the integration response to the method response without modification.response_parameters
- (Optional) Map of response parameters that can be read from the backend response. For example: response_parameters = { "method.response.header.X-Some-Header" = "integration.response.header.X-Some-Other-Header" }
.response_templates
- (Optional) Map of templates used to transform the integration response body.selection_pattern
- (Optional) Regular expression pattern used to choose an integration response based on the response from the backend. Omit configuring this to make the integration the default one. If the backend is an AWS
Lambda function, the AWS Lambda function error header is matched. For all other HTTP
and AWS
backends, the HTTP status code is matched.This resource exports no additional attributes.
In Terraform v1.5.0 and later, use an import
block to import aws_api_gateway_integration_response
using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE
. For example:
import {
to = aws_api_gateway_integration_response.example
id = "12345abcde/67890fghij/GET/200"
}
Using terraform import
, import aws_api_gateway_integration_response
using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE
. For example:
% terraform import aws_api_gateway_integration_response.example 12345abcde/67890fghij/GET/200