我拥有以下Swagger定义文件,可以通过AWS控制台中的“导入API”选项将其导入到现有的AWS API Gateway。现在,我想使用CloudFormation模板做同样的事情。我想知道是否可以通过CloudFormation模板使用“ PATHS”更新现有的AWS API Gateway。我已经阅读了AWS中的文档,但是找不到任何信息。 AWS :: ApiGateway :: RestApi资源无法引用现有的AWS API网关。现有的API网关是通过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"
}
]
}
}
}
答案 0 :(得分:0)
,因为您已经从控制台创建了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定义/主体。