amazon-web-servicesterraformaws-api-gatewayterraform-provider-aws

Enable caching for url query parameters in aws api gateway with terraform


resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = aws_api_gateway_rest_api.example.id
  resource_id   = aws_api_gateway_resource.MyDemoResource.id
  http_method   = "ANY"
  authorization = "NONE"

  request_parameters = {
    "method.request.path.proxy" = true
    "method.request.querystring.tableid" = true
  }
}

With this script, I am trying to add a URL query parameter named tableid with caching enabled. But I can see no documentation referring to enabling the caching.

Resulting configuration of this code


Solution

  • To do so, this can be done using cache_key_parameters and cache_namespace below the aws_api_gateway_integration as follows:

    resource "aws_api_gateway_method" "MyDemoMethod" {
      rest_api_id   = aws_api_gateway_rest_api.example.id
      resource_id   = aws_api_gateway_resource.MyDemoResource.id
      http_method   = "ANY"
      authorization = "NONE"
    
      request_parameters = {
        "method.request.path.proxy" = true
        "method.request.querystring.tableid" = true
      }
    }
    
    
    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"
      cache_key_parameters = ["method.request.querystring.tableid"]
      cache_namespace      = "mycache" 
    }
    

    This was introduced in this Pull Request https://github.com/hashicorp/terraform-provider-aws/pull/893.