Configures an API Gateway with a GET method, mock integration, and a 200 OK method response that includes a custom header and a response model.

Terraform Template

resource "aws_api_gateway_integration" "MyDemoIntegration" {
  http_method = aws_api_gateway_method.MyDemoMethod.http_method
  resource_id = aws_api_gateway_resource.MyDemoResource.id
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  type = "MOCK"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  authorization = "NONE"
  http_method = "GET"
  resource_id = aws_api_gateway_resource.MyDemoResource.id
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
}

resource "aws_api_gateway_method_response" "response_200" {
  http_method = aws_api_gateway_method.MyDemoMethod.http_method
  resource_id = aws_api_gateway_resource.MyDemoResource.id

  response_models = {
    application/json = "MyDemoResponseModel"
  }

  response_parameters = {
    method-response-header.X-My-Demo-Header = "false"
    method.response.header.Content-Type = "false"
    method-response-header = "[object Object]"
    method = "[object Object]"
  }
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  status_code = "200"
}

resource "aws_api_gateway_model" "MyDemoResponseModel" {
  content_type = "application/json"
  description = "API response for MyDemoMethod"
  name = "MyDemoResponseModel"
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  schema = jsonencode({
 "$schema" = "http://json-schema.org/draft-04/schema#"
 title = "MyDemoResponse"
 type = "object"
 properties = {
 Message = {
 type = "string"
 }
 }
 })
}

resource "aws_api_gateway_resource" "MyDemoResource" {
  parent_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  path_part = "mydemoresource"
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
}

resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  description = "This is my API for demonstration purposes"
  name = "MyDemoAPI"
}