Akash s
Akash s

Reputation: 127

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

Upvotes: 1

Views: 2632

Answers (2)

Sai Teja Makani
Sai Teja Makani

Reputation: 1

There is a problem here, If you try to remove method.request. query string.tableid from method and integration lateron while applying the method param will be deleted and while updating the integration it will fail as the integration referencing the same parameter from method that has been just removed. Its annoying to add cache key to only integration resource. Just like UI these should be seperated.

Upvotes: 0

Rshad Zhran
Rshad Zhran

Reputation: 636

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.

Upvotes: 4

Related Questions