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 查询参数。但我看不到任何有关启用缓存的文档。
为此,可以使用
cache_key_parameters
下面的 cache_namespace
和
aws_api_gateway_integration
来完成,如下所示:
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。
这里有一个问题,如果你尝试删除method.request。稍后在应用方法参数时从方法和集成中查询 string.tableid 将被删除,并且在更新集成时它将失败,因为集成引用了刚刚删除的方法中的相同参数。仅将缓存密钥添加到集成资源很烦人。就像 UI 一样,它们应该分开。