【问题标题】:Swagger file with AWS Extensions stored in S3 Bucket for API Creation with Cloudformation带有 AWS 扩展的 Swagger 文件存储在 S3 存储桶中,用于使用 Cloudformation 创建 API
【发布时间】:2019-04-15 03:01:53
【问题描述】:

我正在尝试使用这样的 Cloudformation 模板创建 API 网关:

Resources:
 InvoiceApi:
  Type: AWS::ApiGateway::RestApi
  Properties:
    Description: an Api for our Invoicegen App
    Name: !Ref ApiName
    ApiKeySourceType: !Ref ApiKeySourceType
    BinaryMediaTypes:
    - !Ref binaryMediaType1
    - !Ref binaryMediaType2
    BodyS3Location:
     Bucket:
       Fn::ImportValue: !Sub ${EnvironmentName}-SwaggerApiBucket-Name
     Key: swaggertest.yaml
     ETag: !Ref ETag
     EndpointConfiguration:
     Types:
      - REGIONAL
     FailOnWarnings: true
     MinimumCompressionSize: !Ref minimumCompressionSize

S3 Bucket 上的 Swagger-yaml 文件如下所示:

  swagger: '2.0'
  info:
    version: '2016-08-17T18:08:34Z'
    title: InvoicegenAPI
  basePath: "/LATEST"
  schemes:
   - https
  paths:
    /greeting:
       get:
         summary: Get Greeting
         parameters:
          - name: name
            in: query
            required: false
            type: string
        produces:
          - application/json
        responses:
          '200':
            description: 200 response
        x-amazon-apigateway-integration:
          requestTemplates:
            application/json: '{"name": "$input.params(''name'')"}'
          uri:
            Fn::Join:
             - ''
             - - 'arn:aws:apigateway:'
               - Ref: AWS::Region
               - ":lambda:path/2015-03-31/functions/"
               - Fn::GetAtt:
                 - InvoiceLambda
                 - Arn
               - "/invocations"
         responses:
           default:
             statusCode: '200'
         httpMethod: POST
         type: aws

不幸的是,它会抛出这样的错误:

Unable to parse API definition because of a malformed integration at path /greeting. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 2cf08a97-e66f-11e8-afee-fb6b03568b64)

我仔细检查了 Swagger 文件,所有缩进看起来都很好。我错过了什么?

已经有一个线程在处理这个问题,但还没有产生任何解决方案。

Passing ARN reference from CloudFormation to Swagger

提前谢谢

一个

【问题讨论】:

  • summaryparametersFn::Jointype: aws 的缩进关闭。将您的 YAML 粘贴到 editor.swagger.io 以查看错误。
  • 不,这不是问题,它与 AWS 集成有关。

标签: swagger amazon-cloudformation


【解决方案1】:

我认为你的问题在于对引用的 S3 文件使用 BodyS3Location 属性,这可能没有解析 YAML 文件,因此没有解析你的 instricic 函数。

我的建议是您更改为 Body + AWS::Include Transform,类似于 Passing ARN reference from CloudFormation to Swagger 上的建议。试试这个作为你的资源:

Resources:
 InvoiceApi:
  Type: AWS::ApiGateway::RestApi
  Properties:
    Description: an Api for our Invoicegen App
    Name: !Ref ApiName
    ApiKeySourceType: !Ref ApiKeySourceType
    BinaryMediaTypes:
    - !Ref binaryMediaType1
    - !Ref binaryMediaType2
    Body:
      Fn::Transform:
        Name: AWS::Include
        Parameters:
          Location: !Sub 's3://${EnvironmentName}-SwaggerApiBucket-Name/swaggertest.yaml'
    EndpointConfiguration:
    Types:
    - REGIONAL
    FailOnWarnings: true
    MinimumCompressionSize: !Ref minimumCompressionSize

【讨论】:

    猜你喜欢
    • 2020-07-29
    • 1970-01-01
    • 2016-08-23
    • 2020-05-04
    • 2016-12-09
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多