AWS CloudFormation with AWS :: ApiGateway :: RestApi Gives Invalid REST API Identifier

I am trying to create an AWS::ApiGateway::RestApi using CloudFormation but on startup

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

This fails and when viewing in the CloudFormation console, I see that the Invalid REST API identifier specified error.

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 point to BodyS3Location , which points to 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" } } } } } } } } 

Since I provide this file in accordance with the documentation , I do not need to specify the name RestApi, so I do not think that the problem. Any idea on how I will debug that he is unhappy?

Update # 1

I deleted most of my configuration, so the only property I am specifying now 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 w / CloudFormation bug or am I missing something?

+7
amazon-web-services amazon-cloudformation
source share
2 answers

Both the original template and the minimal example โ€œUpdate 1โ€ that you provided were created successfully in my local tests, and I do not see any obvious problems with any of them.

I noticed that the event-log screenshot above the specified UPDATE_FAILED instead of CREATE_FAILED , and I think that the problem is trying to "update" an existing resource.

Is it possible that the original RestAPI resource was manually modified / deleted after the initial creation of the CloudFormation stack? If so, be warned that this violates the โ€œbest practiceโ€ management of all stack resources through AWS CloudFormation and may be the source of the error:

Do not modify stack resources outside of the AWS cloud. This can create a mismatch between your stack template and the current state of your stack resources, which can cause errors when updating or deleting the stack.

To restore, you can change the logical name of the resource (for example, from API to API2 ) and refresh the stack again. This will create a new RestAPI resource separately from the old.

+4
source share

I spent a lot of time replicating using the lorem.json and BodyS3Location materials you provided, but could not reproduce the error. Are more template content or background information missing here?

I think the error might be related to your Swagger template, not CloudFormation. I was able to reproduce the error in the AWS console by intentionally adding an invalid method to the Swagger template ( foobar instead of get ), and then creating a stack. The stack was created successfully, but trying to view the API in the console showed your error.

I even looked at the history of this post and tried to replicate using the original Swagger template, but the stack did not create. This leads me to believe that there is some kind of history in your stack, and perhaps the API resource was originally created, as the error indicates, "An invalid REST API identifier was specified."

+3
source share

All Articles