【问题标题】:terraform api gateway integration with openapi specterraform api 网关与 openapi 规范的集成
【发布时间】:2018-08-15 19:17:10
【问题描述】:

我目前正在使用 json 文件中的开放 api 规范创建一个带有 terraform 的 AWS API 网关。

resource "aws_api_gateway_rest_api" "my_test_gateway" {
  name        = "test_gateway"
  description = "test gateway"
  body        = "${file("assets/test_openapi_spc.json")}"
}

我需要将由上述 openAPI 规范创建的 api 资源映射到 AWS Step Functions。 我如何引用由 openAPI 规范创建的 API Gateway 资源才能创建新的 aws_api_gateway_integration? 通常你会做这样的事情并在 terraform 中描述资源

resource "aws_api_gateway_integration" "test" {
  resource_id = "${aws_api_gateway_resource.my_resource.id}"
}

然而,就我而言,我的 terraform 脚本中没有定义资源 ID,因为它们是由 openAPI 规范创建的。

是否有某种方法可以提取作为 terraform 数据源创建的 api 网关的所有资源,以便我可以引用它们? 不知道我是否在这里遗漏了一些重要的东西。

【问题讨论】:

    标签: amazon-web-services aws-api-gateway terraform aws-step-functions terraform-provider-aws


    【解决方案1】:

    似乎最好的方法是使用 swagger 扩展 https://swagger.io/docs/specification/openapi-extensions/

    API 资源的集成部分可以驻留在您的 Swagger 规范中。

    就像在 aws API Gateway 扩展中提到的那样招摇https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html

    因此,例如,如果您想将资源映射到步进函数,您可以这样做:

          x-amazon-apigateway-integration:
        credentials: "arn:aws:iam::my_account:role/ApiGWToStepFunction"
        responses:
          default:
            statusCode: "201"
        uri: "arn:aws:apigateway:my_zone:states:action/StartExecution"
        passthroughBehavior: "when_no_templates"
        httpMethod: "POST"
        type: "aws"
    

    我还没说完,但我认为应该是arn:aws:apigateway:my_zone:states:action/StartExecution 而不是arn:aws:apigateway:my_zone:states:your_step_function_name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-30
      • 2019-12-05
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2020-09-22
      • 2020-06-16
      相关资源
      最近更新 更多