【问题标题】:How to update an existing AWS API Gateway using CloudFormation Template如何使用 CloudFormation 模板更新现有 AWS API Gateway
【发布时间】:2019-07-12 01:08:58
【问题描述】:

我有以下 Swagger 定义文件,我可以通过 AWS 控制台中的“导入 API”选项将其导入现有的 AWS API Gateway。现在,我想使用 CloudFormation 模板做同样的事情。我想知道是否可以通过 CloudFormation 模板使用“PATHS”更新现有的 AWS API Gateway。我已阅读 AWS 中的文档,但找不到任何信息。 AWS::ApiGateway::RestApi 资源无法引用现有的 AWS API Gateway。现有 API Gateway 是从 AWS 控制台手动创建的(即,不是通过 CloudFormation 模板创建的)

{
    "openapi": "3.0.1",
    "info": {
        "title": "Common API",
        "description": "defaultDescription",
        "version": "0.3"
    },
    "servers": [
        {
            "url": "http://localhost:32780"
        }
    ],
    "paths": {
        "/catalogs": {
            "get": {
                "description": "Auto generated using Swagger Inspector",
                "parameters": [
                    {
                        "name": "language",
                        "in": "query",
                        "required": false,
                        "style": "form",
                        "explode": true,
                        "example": "en"
                    },
                    {
                        "name": "category",
                        "in": "query",
                        "required": false,
                        "style": "form",
                        "explode": true,
                        "example": "region"
                    },
                    {
                        "name": "subcategory",
                        "in": "query",
                        "required": false,
                        "style": "form",
                        "explode": true,
                        "example": "group"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Auto generated using Swagger Inspector",
                        "content": {
                            "application/json;charset=UTF-8": {
                                "schema": {
                                    "type": "string"
                                },
                                "examples": {}
                            }
                        }
                    }
                },
                "servers": [
                    {
                        "url": "http://localhost:32780"
                    }
                ]
            },
            "servers": [
                {
                    "url": "http://localhost:32780"
                }
            ]
        }
    }
    }

【问题讨论】:

    标签: aws-api-gateway


    【解决方案1】:

    因为您已经从控制台创建了 API 并尝试更新它。不确定 CFT 是否可以提供帮助,但您可能可以尝试一次。由于 CloudFormation 能够调整/更新部署在相同 API 名称或 API 密钥下的 API。
    因此,您可能可以记下您从控制台创建的 API 的名称,并尝试通过 CloudFormation 创建/部署具有相同名称的 API。

    RestAPI:
        Type: AWS::Serverless::Api
        Properties:
          Name: !Sub "your ApiName from the console"        
          StageName: !Sub "dev"
          DefinitionBody:
            "Fn::Transform":
              Name: "AWS::Include"
              Parameters:
                Location: !Sub "s3://${TemporaryBucket}/openapi.yaml"
    

    除了从 S3 调用 API,还可以在 Cloudformation 模板本身中轻松定义 API 定义/主体。

    【讨论】:

    • 我试过这个。它只是创建另一个同名的 API 网关。
    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 2021-10-14
    • 2017-07-26
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 2020-04-21
    • 2018-02-03
    相关资源
    最近更新 更多