如何在 ApiGateway 中获取根资源的资源路径?
How do I get resource path for Root Resource in ApiGateway?
我正在尝试使用 terraform 为根资源的 GET/OPTIONS 方法更改 api 网关中的缓存设置。
resource "aws_api_gateway_method_settings" "root_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.default.id
stage_name = terraform.workspace
method_path = "<root resource path>/GET"
settings {
metrics_enabled = true
logging_level = "INFO"
caching_enabled = true
}
}
我在 method_path
参数上遇到问题,因为我无法找出 <根资源路径>.
的正确值
method_path
对于任何其他资源,例如 {proxy+} 资源如下所示:
resource "aws_api_gateway_method_settings" "proxy_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.default.id
stage_name = terraform.workspace
method_path = "{proxy+}/GET"
}
路径是"~1/GET"
。下面是完整的工作示例:
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_deployment" "test" {
depends_on = [aws_api_gateway_integration.test]
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
stage_name = "prod"
}
resource "aws_api_gateway_integration" "test" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "MOCK"
}
resource "aws_api_gateway_method_settings" "root_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
stage_name = "prod"
method_path = "~1/GET"
settings {
metrics_enabled = true
logging_level = "INFO"
caching_enabled = true
}
depends_on = [aws_api_gateway_deployment.test]
}
我正在尝试使用 terraform 为根资源的 GET/OPTIONS 方法更改 api 网关中的缓存设置。
resource "aws_api_gateway_method_settings" "root_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.default.id
stage_name = terraform.workspace
method_path = "<root resource path>/GET"
settings {
metrics_enabled = true
logging_level = "INFO"
caching_enabled = true
}
}
我在 method_path
参数上遇到问题,因为我无法找出 <根资源路径>.
method_path
对于任何其他资源,例如 {proxy+} 资源如下所示:
resource "aws_api_gateway_method_settings" "proxy_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.default.id
stage_name = terraform.workspace
method_path = "{proxy+}/GET"
}
路径是"~1/GET"
。下面是完整的工作示例:
resource "aws_api_gateway_rest_api" "MyDemoAPI" {
name = "MyDemoAPI"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_method" "MyDemoMethod" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_deployment" "test" {
depends_on = [aws_api_gateway_integration.test]
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
stage_name = "prod"
}
resource "aws_api_gateway_integration" "test" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
http_method = aws_api_gateway_method.MyDemoMethod.http_method
type = "MOCK"
}
resource "aws_api_gateway_method_settings" "root_get_method_settings" {
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
stage_name = "prod"
method_path = "~1/GET"
settings {
metrics_enabled = true
logging_level = "INFO"
caching_enabled = true
}
depends_on = [aws_api_gateway_deployment.test]
}