Swagger file with AWS Extensions stored in S3 Bucket for API Creation with Cloudformation

…衆ロ難τιáo~ 提交于 2020-01-06 08:28:12

问题


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:


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


来源:https://stackoverflow.com/questions/53261354/swagger-file-with-aws-extensions-stored-in-s3-bucket-for-api-creation-with-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!