使用 terraform 在 aws api 网关中为 url 查询参数启用缓存
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
}
}
使用此脚本,我试图添加一个名为 tableid 的 URL 查询参数并启用缓存。但是我看不到任何关于启用缓存的文档。
为此,可以使用 aws_api_gateway_integration
下方的 cache_key_parameters
和 cache_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"
}
这是在此合并请求中引入的 https://github.com/hashicorp/terraform-provider-aws/pull/893。
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 查询参数并启用缓存。但是我看不到任何关于启用缓存的文档。
为此,可以使用 aws_api_gateway_integration
下方的 cache_key_parameters
和 cache_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"
}
这是在此合并请求中引入的 https://github.com/hashicorp/terraform-provider-aws/pull/893。