amazon-web-services - 将 OpenAPI 规范中描述的 REST API 转换为 Terraform 模板中描述的 AWS API Gateway REST API

标签 amazon-web-services swagger terraform aws-api-gateway openapi

我的 REST API 有 OpenAPI 3.0 规范 (YAML),我需要在 Terraform 模板 (HCL) 中描述与 AWS API Gateway 资源相同的 REST API。

有什么工具可以帮我自动转换吗?

最佳答案

AWS 的 API Gateway directly supports importing an OpenAPI 3.0 spec定义 API 网关的所有相关部分。

使用 Terraform 这可以通过 aws_api_gateway_rest_api resource 来完成和 body parameter .

tests for the resource 中给出了一个示例:

resource "aws_api_gateway_rest_api" "test" {
  name = "foo"
  body = <<EOF
{
  "swagger": "2.0",
  "info": {
    "title": "foo",
    "version": "2017-04-20T04:08:08Z"
  },
  "schemes": [
    "https"
  ],
  "paths": {
    "/test": {
      "get": {
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "x-amazon-apigateway-integration": {
          "type": "HTTP",
          "uri": "https://www.google.de",
          "httpMethod": "GET",
          "responses": {
            "default": {
              "statusCode": 200
            }
          }
        }
      }
    }
  }
}
EOF
}

您还可以使用 file 函数直接从 YAML 文件加载 OpenAPI 规范:

resource "aws_api_gateway_rest_api" "test" {
  name = "foo"
  body = file("${path.module}/api.yml")
}

关于amazon-web-services - 将 OpenAPI 规范中描述的 REST API 转换为 Terraform 模板中描述的 AWS API Gateway REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60214612/

相关文章:

reactjs - CORS政策: No 'Access-Control-Allow-Origin' - AWS and Vercel

amazon-web-services - Appsync 查询联合返回类型抛出 400

具有默认值的枚举的 C# Swagger 生成

bash - terraform循环外部输入

azure - 如何在 Terraform 中插入 COUNT?

terraform - 更新到 terraform 版本 0.12.26 后出现 "Ambiguous attribute key"错误

google-app-engine - 最终 GAE 与 AWS 架构决策

amazon-web-services - 如何使用 lambda Java SDK 从 SQS 读取所有消息,聚合所有这些消息并将它们作为单个 JSON 文件存储到 S3 存储桶?

spring-boot - 从SpringFox2.x升级到SpringFox3.0开放API

java - Swagger 错误 预期类型为字符串,但发现类型为整数