我正在尝试使用如下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存储桶上的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
提前谢谢
A
答案 0 :(得分:0)
我认为您的问题是对引用的S3文件使用BodyS3Location
属性,该属性可能不解析YAML文件,因此无法解析您的复杂功能。
我的建议是您更改为“正文+ AWS::Include转换”,类似于在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