我正在尝试通过Cloudformation创建一个API网关,使用Swagger定义API,因为我遇到了一些问题(见下文),将其设置为Cloudformation资源 .

这是我的Cloudformation模板的大块,它定义了Api(主要取自here):

"Api": {
    "Type": "AWS::ApiGateway::RestApi",
    "Properties": {
        "Name": {
            "Fn::Join": [
                "",
                [
                    {
                        "Ref": "paramProjectName"
                    },
                    "_API"
                ]
            ]
        },
        "Description": {
            "Fn::Join": [
                "",
                [
                    "Created by ",
                    {
                        "Ref": "paramScriptName"
                    }
                ]
            ]
        },
        "FailOnWarnings": true,
        "Body": {
            "swagger": "2.0",
            "info": {
                "version": "2016-08-18T18:08:34Z",
                "title": "Slack API"
            },
            "basePath": "/LATEST",
            "schemes": ["https"],
            "paths": {
                "/slack": {
                    "post": {
                        "parameters": [],
                        "produces": ["application/json"],
                        "responses": {
                            "200": {
                                "description": "200 response"
                            }
                        },
                        "x-amazon-apigateway-integration": {
                            "uri": {"Fn::Join": ["", [
                                "arn:aws:apigateway:",
                                {"Ref": "AWS::Region"},
                                ":lambda:path/2015/03/31/functions/",
                                {"Fn::GetAtt": ["Lambda", "Arn"]},
                                "/invocations"
                            ]]},
                            "responses": {
                                "default": {
                                    "statusCode": "200"
                                }
                            },
                            "httpMethod": "POST",
                            "type": "aws"
                        }
                    }
                }
            }
        }
    }
},

这是我的构建规范:

version: 0.1
phases:
  install:
    commands:
      - aws cloudformation package --template-file template.json --s3-bucket scubbo-slackbot-3-bucket
                                   --output-template-file outputTemplate.yml
artifacts:
  type: zip
  files:
    - outputTemplate.yml
    - index.py

但是当我尝试使用CodePipeline的CloudFormation部署步骤进行部署时,它会因 Body cannot be specified together with BodyS3Location 而失败 . 我'm confused, because I don'吨在我的仓库中看到字符串 BodyS3Location . This似乎暗示,在过去的某个时间, BodyS3Location 是默认创建的,但看起来这个bug已被修复 .

下面的原始问题,关于上下文


(原 Headers :'Cloudformation Api更新失败,“无效的Swagger 2.0输入”')

我正在尝试设置CodePipeline(通过Cloudformation)从GitHub仓库中提取更新并更新Lambda函数(主要由herehere引导) .

但是,当CodePipeline的最后一步执行时,对现有堆栈的更新失败(更新 AWS::ApiGateway::RestApi ,模板中的第一个资源)时出现 Invalid Swagger 2.0 input

我怀疑(根据结果如this和ivectbor的评论here)这与从json到yml的转换导致错误的引用(单引号而不是双引号)有关 . 但是,当我在 buildspec.yml 中添加选项 --use-json 时,构建将失败 Unknown option . 如果我尝试 --use-json true--use-json True 相同(整个互联网似乎更喜欢yml到json - 我找不到任何复制用法的例子)

这里's a snippet of the template I' m尝试在CodePipeline的Deploy步骤中执行:

"Api": {
    "Type": "AWS::ApiGateway::RestApi",
    "Properties": {
        "Name": {
            "Fn::Join": [
                "",
                [
                    {
                        "Ref": "paramProjectName"
                    },
                    "_API"
                ]
            ]
        },
        "Description": {
            "Fn::Join": [
                "",
                [
                    "Created by ",
                    {
                        "Ref": "paramScriptName"
                    }
                ]
            ]
        },
        "FailOnWarnings": true
    }
}

使用buildspec:

version: 0.1
phases:
  install:
    commands:
      - aws cloudformation package --template-file template.json --s3-bucket {BUCKET-NAME}
                                   --output-template-file outputTemplate.yml
artifacts:
  type: zip
  files:
    - outputTemplate.yml
    - index.py

我无法保证这与正在使用的输出模板文件相同,但以下是在本地运行 aws cloudformation package 命令的结果:

Resources:
  Api:
    Properties:
      Description:
        Fn::Join:
        - ''
        - - 'Created by '
          - Ref: paramScriptName
      FailOnWarnings: true
      Name:
        Fn::Join:
        - ''
        - - Ref: paramProjectName
          - _API
    Type: AWS::ApiGateway::RestApi

当然包括 ' .

我将我的模板更新为YML格式(并用 " 替换了所有 ' ),但仍然收到"Invalid Swagger 2.0 format"消息 .