【问题标题】:Enable caching for url query parameters in aws api gateway with terraform使用 terraform 在 aws api 网关中启用 url 查询参数的缓存
【发布时间】:2022-01-24 08:36:52
【问题描述】:
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
  }
}

使用此脚本,我正在尝试添加一个名为 tableid 的 URL 查询参数,并启用缓存。但我看不到有关启用缓存的文档。

【问题讨论】:

    标签: amazon-web-services terraform aws-api-gateway terraform-provider-aws


    【解决方案1】:

    为此,可以使用 aws_api_gateway_integration 下方的 cache_key_parameterscache_namespace 来完成,如下所示:

    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" 
    }
    

    这是在此 Pull Request https://github.com/hashicorp/terraform-provider-aws/pull/893 中介绍的。

    【讨论】:

    • 谢谢!!。 aws_api_gateway_method 中不允许使用 cache_key_parameterscache_namespace。我在 aws_api_gateway_integration 中为相同的方法添加了它,而没有更改 aws_api_gateway_method 上的任何内容并且它起作用了。
    • 感谢您的测试。我刚刚确定了答案!
    猜你喜欢
    • 2017-12-01
    • 2018-07-30
    • 1970-01-01
    • 2019-05-27
    • 2021-08-16
    • 1970-01-01
    • 2023-03-10
    • 2019-12-05
    • 2019-03-16
    相关资源
    最近更新 更多