AWS API Gateway: missing AWS Service Proxy; HTTP Headers; Request Body Passthrough

2,179 views
Skip to first unread message

dav...@brightscope.com

unread,
Jun 8, 2016, 10:23:39 PM6/8/16
to Terraform

We're trying to recreate our API Gateway with Terraform 0.6.16, but we're having some issues with the aws_api_gateway_integration resource, and it's not entirely clear if these qualify as bugs, missing features, or lack of understanding a somewhat non-obvious problem.

Our resource definition (with sensitive bits removed):

resource "aws_api_gateway_integration" "<xxx>_post_integration" {
  rest_api_id
= "${aws_api_gateway_rest_api.<api_name>.id}"
  resource_id
= "${aws_api_gateway_resource.<resource_name>.id}"
  http_method
= "${aws_api_gateway_method.<method_name>.http_method}"
  type
= "AWS"
  uri
= "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${var.region}:<account_id>:function:<function_name>/invocations"
  credentials
= "arn:aws:iam::<account_id>:role/<role_name>"
  integration_http_method
= "POST"
  request_templates
= {
   
"application/x-www-form-urlencoded" = "{ \"body\": $input.json(\"$\") }"
 
}
  request_parameters_in_json
= <<PARAMS
 
{
   
"X-Amz-Invocation-Type": "Event"
 
}
PARAMS
}

Here are screenshots depicting the settings we are trying to recreate:

  • Per the documentation, the integration input type can only be HTTP, MOCK, or AWS. The integration type that wound up being selected in the console was the Lambda Function. Although it's not exactly inaccurate, given that the URI does point to a Lambda function, there doesn't seem to be a way to get it to use the AWS Service Proxy.
  • I'm under the impression that request_parameters_in_json can be used to set the HTTP headers for the request. As they stand now, the request_parameters_in_json setting will produce the following error when trying to call terraform apply:
  • There are no apparent settings for the Request Body Passthrough. It seems to default to "When no template matches the request Content-Type header", when we want "When there are no templates defined (recommended)".
aws_api_gateway_integration.<resource_name>: Error creating API Gateway Integration: BadRequestException: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: Event, Invalid mapping expression specified: X-Amz-Invocation-Type]
status code
: 400, request id: <request_id>


I had to remove the request_parameters_in_json setting to get terrform apply to work. This is how it created the resource, taking into consideration my bullet points above:


Reply all
Reply to author
Forward
0 new messages