swagger - 带有 AWS 扩展的 Swagger 文件存储在 S3 存储桶中,用于使用 Cloudformation 创建 API
问题描述
我正在尝试使用这样的 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 文件,所有缩进看起来都很好。我错过了什么?
已经有一个线程在处理这个问题,但还没有产生任何解决方案。
将 ARN 引用从 CloudFormation 传递给 Swagger
提前谢谢
一个
解决方案
我认为你的问题是使用BodyS3Location
引用的 S3 文件的属性,它可能没有解析 YAML 文件,因此没有解析你的 instricic 函数。
我的建议是您更改为 Body + AWS::Include Transform,类似于将ARN 参考从 CloudFormation 传递到 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
推荐阅读
- python - zip函数python - 奇怪的行为
- javascript - 如何将函数应用于从本地存储创建的表
- awk - 对于字段中的每个不同出现,打印具有关联的最大值的行
- linux - 在 Go 中调用 mremap 不起作用,但没有错误
- maven - 添加到 POM.xml 文件的依赖项不会显示在 Maven 依赖项下
- amazon-ec2 - Ansible 2.8 无法使用 [0] 表示法解析动态 EC2 主机
- c++ - 如何使用结构体、类型定义和模板?
- azure-sql-database - 用户无法查询 azure sql 数据库中的一个特定表 - 获取错误代码 8630
- java - JUnit4:测试类型为 ArrayList 的读取文件方法
- python-3.x - 通过python中的文件查询MariaDB