仅供参考-我已经检查了与此相关的类似问题,但都没有解决我的问题。
我正在尝试为AWS Api-Gateway下的许多Api创建Swagger定义。我可以通过从API阶段下载的自动生成的YAML配置,成功地对其他(POST、GET)端点执行此操作。
但是,当我尝试使用Lambda代理集成对Api-Gateway端点执行同样的操作时,我遇到了问题:Error from Swagger editor.swagger.io
下面是我对失败端点的YAML定义:
swagger: "2.0"
info:
version: "2018-04-18T17-09-07Z"
title: "XXX API"
host: "api.xxx.io"
schemes:
- "https"
parameters:
stage:
name: stage
in: path
type: string
enum: [ staging, production]
required: true
paths:
/env/{stage}/{proxy+}:
x-amazon-apigateway-any-method:
produces:
- "application/json"
parameters:
- $ref: '#/parameters/stage'
- name: "proxy"
in: "path"
required: true
type: "string"
responses: {}
x-amazon-apigateway-integration:
uri: "arn:aws:apigateway:eu-central-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-central-1:xxxxxxxxx:function:environment/invocations"
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
cacheNamespace: "4vbcjm"
cacheKeyParameters:
- "method.request.path.proxy"
contentHandling: "CONVERT_TO_TEXT"
type: "aws_proxy"这与亚马逊网络服务的文档是一致的:enter link description here
拜托,我错过了什么?
发布于 2020-01-21 01:56:36
乍一看,我认为您的parameters代码块中存在错误。如果您包含一个$ref,它将丢弃该块后面的所有内容,因此您的代理名称将被删除。我有一个类似的api-gateway设置,将所有调用代理到一个lambda,这是我的参数块:
parameters:
- name: "proxy"
in: "path"
required: true
type: "string"此外,如果您担心DDoS或提供安全数据,则可能需要一个授权器。方法是添加一个security数组作为参数的兄弟,并添加一个securityDefinitions块作为paths的兄弟
security:
- authorizer: []
securityDefinitions:
authorizer:
type : "apiKey"
name : "Authorization"
in : "header"
x-amazon-apigateway-authtype : "custom"
x-amazon-apigateway-authorizer : {
type : "request",
authorizerUri : "arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${region}:${account_id}:function:${authorizer_function_name}/invocations",
authorizerResultTtlInSeconds : 58,
identitySource: "method.request.header.authorization",
}*请注意,我将swagger发布为terraform模板,因此使用${}替换。
https://stackoverflow.com/questions/50681853
复制相似问题