带有存储在S3存储桶中的AWS扩展的Swagger文件,用于使用Cloudformation创建API [英] Swagger file with AWS Extensions stored in S3 Bucket for API Creation with Cloudformation

查看:134
本文介绍了带有存储在S3存储桶中的AWS扩展的Swagger文件,用于使用Cloudformation创建API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 资源:
InvoiceApi :
类型:AWS :: ApiGateway :: RestApi
属性:
描述:Invoicegen应用程序的api
名称:!Ref ApiName
ApiKeySourceType:!Ref ApiKeySourceType
BinaryMediaTypes:
-!Ref binaryMediaType1
-!Ref binaryMediaType2
BodyS3位置:
存储桶:
Fn :: ImportValue:!Sub $ {EnvironmentName}- SwaggerApiBucket-Name
键:swaggertest.yaml
ETag:!Ref ETag
EndpointConfiguration:
类型:
-区域
FailOnWarnings:真
MinimumCompressionSize:!Ref minimumCompressionSize

S3存储桶上的Swagger-yaml文件如下所示:

 挥舞:'2.0'
信息:
版本:'2016-08-17T18:08:34Z'
标题:InvoicegenAPI
basePath: / LATE ST
方案:
-https
路径:
/问候语:
得到:
摘要:获取问候
参数:
-名称:name
in:查询
必需:false
类型:string
产生:
-application / json
响应:
'200':
描述:200响应
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
响应:
默认值:
statusCode:'200'
httpMethod:POST
类型:aws

不幸的是,它引发了这样的错误:

 由于路径/ greeting的集成格式错误,无法解析API定义。 (服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求ID:2cf08a97-e66f-11e8-afee-fb6b03568b64)

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



已经有一个线程在处理此问题,但尚未产生任何解决方案。



将ARN参考从CloudFormation传递到Swagger



预先谢谢



A

解决方案

我认为您的问题是对引用的S3文件使用 BodyS3Loc​​ation 属性,该属性可能不会解析YAML文件,因此无法解析您的复杂功能。 / p>

我的建议是您更改为Body + AWS :: Include 转换,类似于在< a href = https://stackoverflow.com/questions/41266488/passing-arn-reference -from-cloudformation-to-swagger#42779465>将ARN参考从CloudFormation传递到Swagger 。尝试将其作为资源:

 资源:
InvoiceApi:
类型:AWS :: ApiGateway :: RestApi
属性:
说明:Invoicegen应用程序$ a $$的Api名称:!Ref ApiName
ApiKeySourceType:!Ref ApiKeySourceType
BinaryMediaTypes:
-!Ref binaryMediaType1
-!Ref binaryMediaType2
正文:
Fn :: Transform:
名称:AWS :: Include
参数:
位置:!Sub's3:// $ {EnvironmentName} -SwaggerApiBucket-Name / swaggertest.yaml'
EndpointConfiguration:
类型:
-区域
FailOnWarnings:真实
MinimumCompressionSize:!Ref minimumCompressionSize


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

解决方案

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

这篇关于带有存储在S3存储桶中的AWS扩展的Swagger文件,用于使用Cloudformation创建API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆