AWS CloudFormation w/ AWS::ApiGateway::RestApi gives Invalid REST API identifier specified

11,682

Solution 1

Both the original template and the "Update 1" minimal example you provided created successfully in my local tests, and I don't see any obvious issues with either of them.

I noticed that the event-log screenshot above said UPDATE_FAILED instead of CREATE_FAILED, and think the issue is somewhere in the attempt to "update" the existing resource.

Is it possible that the original RestAPI resource was manually modified/deleted after the CloudFormation stack's initial creation? If so, be warned that this violates the "Manage All Stack Resources Through AWS CloudFormation" best practice, and could be the source of the error:

Do not make changes to stack resources outside of AWS CloudFormation. Doing so can create a mismatch between your stack's template and the current state of your stack resources, which can cause errors if you update or delete the stack.

To recover, you could change the logical name of the resource (e.g., from API to API2) and update the stack again. This will cause a new RestAPI resource to be created separately from the old one.

Solution 2

I spent a good while trying to replicate using the lorem.json and BodyS3Location content you provided, but was unable to reproduce the error. Is there some more template content or background information missing here?

I think the error may lie with your Swagger template, not CloudFormation. I was able to reproduce the error in the AWS console by deliberately adding an invalid method to the Swagger template (foobar instead of get), then creating the stack. The stack was created successfully, but trying to view the API in the console displayed your error.

I even looked at the history of this post and tried to replicate using the original Swagger template, but the stack would not create. This leads me to believe there's some history with your stack, and maybe the API resource was created initially with, as the error suggests, an "Invalid REST API identifier specified".

Share:
11,682

Related videos on Youtube

Kyle Decot
Author by

Kyle Decot

I'm a Senior Software Engineer at ROOT Insurance in Columbus Ohio. We use Ruby/Rails, React Native, PostgreSQL, Swift, Objective-C, and Java but I also enjoy exploring Erlang and Elixir.

Updated on June 04, 2022

Comments

  • Kyle Decot
    Kyle Decot over 1 year

    I'm attempting to create an AWS::ApiGateway::RestApi resource using CloudFormation but when running

    aws cloudformation deploy --template-file lorem.json --stack-name lorem

    This ends up failing and upon looking in the CloudFormation console I see that the error is Invalid REST API identifier specified.

    enter image description here

    Here is my lorem.json file:

    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Description": "lorem.io Stack",
      "Resources": {
        "API": {
          "Type" : "AWS::ApiGateway::RestApi",
          "Properties" : {
            "FailOnWarnings": true,
            "BodyS3Location": {
              "Bucket": "cloudformation.lorem.io",
              "Key": "open-api.json"
            }
          }
        }
      }
    }
    

    Here I'm specifying BodyS3Location which points at an S3 object that contains the following:

    {
      "swagger": "2.0",
      "info": {
        "title": "Lorem.IO API",
        "version": "1.0.0"
      },
      "definitions": {
        "Generator": {
          "type": "object",
          "properties": {
            "title": {
              "type": "string"
            }
          }
        }
      },
      "produces": [
        "application/json"
      ],
      "paths": {
        "/generators": {
          "get": {
            "responses": {
              "200": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/Generator"
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Because I'm providing this file according to the documentation I shouldn't have to provide the name of the RestApi so I don't think that's the problem. Any idea on how I would go about debugging exactly what it's unhappy about?

    Update #1

    I've stripped out a lot of my configuration so that the only property that I'm now specifying is name and I still get the same error (Invalid REST API identifier specified):

    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Description": "lorem.io Stack",
      "Resources": {
        "API": {
          "Type" : "AWS::ApiGateway::RestApi",
          "Properties" : {
            "FailOnWarnings": true,
            "Name": "Hello World"
          }
        }
      }
    }
    

    According to the documentation Name is the only required attribute - Is this a bug w/ CloudFormation or am I missing something?

  • mseebach
    mseebach over 6 years
    I had this issue after manually deleting a Cloudformation-created API in the API Gateway console. Deleting the CF stack and re-creating it solved the problem.