Swagger file with AWS Extensions stored in S3 Buck

2019-08-21 09:20发布

I'm trying to create an API Gateway using a Cloudformation template like this:

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

the Swagger-yaml file on the S3 Bucket looks like this:

  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

unfortunately it throws an error like this:

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)

I double checked the Swagger file, all the indents seem fine. What am I missing?

There is a thread dealing with this issue already but has not yielded any solution yet.

Passing ARN reference from CloudFormation to Swagger

merci in advance

A

1条回答
疯言疯语
2楼-- · 2019-08-21 10:19

I think you problem is on using the BodyS3Location property for the referenced S3 file, which is probably not parsing the YAML file, therefore not resolving your instricic functions.

My suggestion is that you change to Body + AWS::Include Transform, similar to what was suggested on Passing ARN reference from CloudFormation to Swagger. Try this as your Resource:

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
查看更多
登录 后发表回答