1
votes

I have the following Swagger definition file that I was able to import to an existing AWS API Gateway through "Import API" option in the AWS Console. Now, I would like to do the same thing using a CloudFormation template. I would like to know if I can update an existing AWS API Gateway with the 'PATHS' through CloudFormation template. I have read the documentation in AWS, but I couldn't find any information. The AWS::ApiGateway::RestApi resource have no way of referring to an existing AWS API Gateway. The existing API Gateway was created manually from the AWS console (i.e, not created through CloudFormation template)

{
    "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"
                }
            ]
        }
    }
    }
1

1 Answers

0
votes

as you have already created your API from the Console and trying to update it. Not sure whether the CFT can help but probably you can try once. As CloudFormation is capable of modulating/updating the API deployed under the same API Name or API Key.
So, you can probably note down the Name of the API you have created from the Console and try creating/deploying the API with the same name through CloudFormation.

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"

Instead of calling the API from S3, the API Defition/Body can also be defined in the Cloudformation template itself for ease.