在 AWS API Gateway 中,我有一个端点定义为 /users/{userId}/someAction
,我正在尝试用 terraform 重新创建它
我会开始拥有某种链接的 gateway_resource 链,就像这样......
resource "aws_api_gateway_resource" "Users" {
rest_api_id = "${var.rest_api_id}"
parent_id = "${var.parent_id}"
path_part = "users"
}
//{userId} here?
resource "aws_api_gateway_resource" "SomeAction" {
rest_api_id = "${var.rest_api_id}"
parent_id = "${aws_api_gateway_resource.UserIdReference.id}"
path_part = "someAction"
}
然后我在其中定义了
aws_api_gateway_method
和其他一切。如何在 terraform 中定义此端点? terraform 文档和示例未涵盖此用例。
最佳答案
您需要定义一个 resource谁的path_part
是您要使用的参数:
// List
resource "aws_api_gateway_resource" "accounts" {
rest_api_id = var.gateway_id
parent_id = aws_api_gateway_resource.finance.id
path_part = "accounts"
}
// Unit
resource "aws_api_gateway_resource" "account" {
rest_api_id = var.gateway_id
parent_id = aws_api_gateway_resource.accounts.id
path_part = "{accountId}"
}
然后你创建 method和 启用 路径参数:
resource "aws_api_gateway_method" "get-account" {
rest_api_id = var.gateway_id
resource_id = var.resource_id
http_method = "GET"
authorization = "NONE"
request_parameters = {
"method.request.path.accountId" = true
}
}
最后,您可以在 integration 中成功创建映射。 :
resource "aws_api_gateway_integration" "get-account-integration" {
rest_api_id = var.gateway_id
resource_id = var.resource_id
http_method = aws_api_gateway_method.get-account.http_method
type = "HTTP"
integration_http_method = "GET"
uri = "/integration/accounts/{id}"
passthrough_behavior = "WHEN_NO_MATCH"
request_parameters = {
"integration.request.path.id" = "method.request.path.accountId"
}
}
该方法需要在那里 - 并启用参数 - 以便集成映射工作。
关于amazon-web-services - 在 Terraform 中,如何使用请求路径中的变量指定 API 网关端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39040739/