首页 > 解决方案 > 如何通过 Terraform 描述 API Gateway 资源?

问题描述

我正在尝试使用该ANY方法用 Terraform 描述我的 API 网关资源。我有:

/{accountId}/{accountType}/ANY

集成类型为 Lambda 函数并启用 Lambda 代理集成。

到目前为止,我有这个:

resource "aws_api_gateway_rest_api" "apiLambda" {
  name        = "account-api-proxy-main"
  description = "Proxy to handle requests to the Account service lambda"
}

resource "aws_api_gateway_resource" "accountIdResource" {
  rest_api_id = aws_api_gateway_rest_api.apiLambda.id
  parent_id   = aws_api_gateway_rest_api.apiLambda.root_resource_id
  path_part   = "{accountId}"
}

resource "aws_api_gateway_resource" "accountTypeResource" {
  rest_api_id = aws_api_gateway_rest_api.apiLambda.id
  parent_id   = aws_api_gateway_resource.accountIdResource.id
  path_part   = "{accountType}"
}

resource "aws_api_gateway_method" "any_method" {
  rest_api_id   = aws_api_gateway_rest_api.apiLambda.id
  resource_id   = aws_api_gateway_resource.accountTypeResource.id
  http_method   = "ANY"
  authorization = "NONE"

  request_parameters = {
    "method.request.path.accountId" = true
    "method.request.path.accountType" = true
  }
}

我不太确定如何描述 lambda 函数集成以及 lambda 代理集成......任何指针?我通过控制台创建了 API 网关,一切正常,但我现在正尝试通过 terraform 重新创建所有配置。

标签: amazon-web-servicesaws-lambdaterraformaws-api-gateway

解决方案


推荐阅读