我正在尝试使用CloudFormation但在运行时创建 AWS::ApiGateway::RestApi
资源
aws cloudformation deploy --template-file lorem.json --stack-name lorem
这最终失败了,在查看CloudFormation控制台时,我发现错误是 Invalid REST API identifier specified
.
这是我的 lorem.json
文件:
{
"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"
}
}
}
}
}
这里我指定的 BodyS3Location
指向包含以下内容的S3对象:
{
"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"
}
}
}
}
}
}
}
}
因为我根据documentation提供这个文件我不应该认为's the problem. Any idea on how I would go about debugging exactly what it'不满意吗?
更新#1
我've stripped out a lot of my configuration so that the only property that I'现在指定的是 name
,我仍然得到相同的错误( 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"
}
}
}
}
根据documentation Name
是唯一必需的属性 - 这是一个带有CloudFormation的错误还是我错过了什么?
2 回答
原始模板和您提供的“Update 1”最小示例都在我的本地测试中成功创建,我没有看到任何明显的问题 .
我注意到上面的事件日志截图说
UPDATE_FAILED
而不是CREATE_FAILED
,并且认为问题是在某个地方尝试"update"现有资源 .在CloudFormation堆栈初始创建之后,是否可能手动修改/删除了原始
RestAPI
资源?如果是这样,请注意这违反了“Manage All Stack Resources Through AWS CloudFormation”最佳做法,并且可能是错误的来源:要恢复,您可以更改资源的逻辑名称(例如,从
API
更改为API2
)并再次更新堆栈 . 这将导致与旧资源分开创建新的RestAPI
资源 .我花了很多时间尝试使用您提供的
lorem.json
和BodyS3Location
内容进行复制,但无法重现错误 . 此处是否缺少更多模板内容或背景信息?我认为错误可能在于您的Swagger模板,而不是CloudFormation . 我能够通过故意向Swagger模板(
foobar
而不是get
)添加无效方法来重现 AWS console 中的错误,然后创建堆栈 . 堆栈已成功创建,但尝试在控制台中查看API时显示错误 .我甚至查看了这篇文章的历史,并尝试使用原始的Swagger模板进行复制,但是堆栈不会创建 . 这让我相信您的堆栈有一些历史记录,并且可能最初创建的API资源,如错误所示,"Invalid REST API identifier specified" .