I'm setting up a mock integration for GET requests with AWS API Gateway, and wonder why it only works when the application/json
request template is specified. To my understanding GET request does not have a body and hence does not have a Content-Type header. What is special about 'application/json'? Is this behavior documented somewhere or am I missing some defaults somewhere?
Here is terraform code for my API Gateway:
resource "aws_api_gateway_rest_api" "test-api" {
name = "test-api"
endpoint_configuration {
types = ["REGIONAL"]
}
body = jsonencode(yamldecode(file("openapi.yaml")))
}
openapi: "3.0.1"
info:
version: "1.0"
title: example
paths:
/test:
get:
responses:
"200":
description: demo
headers:
Content-Type: { schema: { type: 'string' } }
x-amazon-apigateway-integration:
type: MOCK
passthroughBehavior: when_no_templates
# the next line is required.
# API Gateway returns 500 error if I remove it. why?
# API Gateway returns 415 error if I change application/json to text/plain. why?
requestTemplates: { 'application/json': '{"statusCode": 200}' }
responses:
default:
statusCode: 200
responseParameters: { 'method.response.header.Content-Type': "'text/plain'" }
responseTemplates: {'text/plain': 'hello'}
Here is an example log output when requestTemplates is set to{ 'text/plain': '{"statusCode": 200}' }
Execution log for request 09c6d06b-669c-4717-86a2-c8489136f760
Fri May 06 14:28:24 UTC 2022 : Starting execution for request: 09c6d06b-669c-4717-86a2-c8489136f760
Fri May 06 14:28:24 UTC 2022 : HTTP Method: GET, Resource Path: /test
Fri May 06 14:28:24 UTC 2022 : Method request path: {}
Fri May 06 14:28:24 UTC 2022 : Method request query string: {}
Fri May 06 14:28:24 UTC 2022 : Method request headers: {}
Fri May 06 14:28:24 UTC 2022 : Method request body before transformations:
Fri May 06 14:28:24 UTC 2022 : Execution failed: null
Fri May 06 14:28:24 UTC 2022 : Method completed with status: 415