[英]Swagger definition for an AWS Api-Gateway Lambda Proxy endpoint
FYI - I've checked similar issues related to this, but none solves my problem.仅供参考 - 我已经检查过与此相关的类似问题,但没有一个能解决我的问题。
I'm trying to create the Swagger definition for a number of APIs under AWS Api-Gateway.我正在尝试为 AWS Api-Gateway 下的许多 API 创建 Swagger 定义。 I'm able to successfully do this for other(POST, GET) endpoints from an auto-generated YAML configuration I downloaded from the API Stage.
我能够从我从 API Stage 下载的自动生成的 YAML 配置中为其他(POST、GET)端点成功执行此操作。
But I encountered issues when I tried to do same for an Api-Gateway endpoint with Lambda Proxy Integration: Error from Swagger editor.swagger.io但是,当我尝试使用 Lambda 代理集成对 Api-Gateway 端点执行相同操作时遇到了问题:来自 Swagger editor.swagger.io 的错误
Below is my YAML definition for the failing endpoint:以下是我对失败端点的 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"
this is inline with AWS Documentation: enter link description here这与 AWS 文档一致: 在此处输入链接描述
Please, what am I missing?请问,我错过了什么?
At a glance I believe you have an error in your parameters
block.乍一看,我相信您的
parameters
块中有错误。 If you include a $ref
it discards anything in that block that follows it, so your proxy name is getting dropped.如果您包含
$ref
它会丢弃该块中的任何内容,因此您的代理名称将被删除。 I have a similar setup with api-gateway proxying all calls to a lambda and this is my parameters block:我有一个类似的设置,api-gateway 代理对 lambda 的所有调用,这是我的参数块:
parameters:
- name: "proxy"
in: "path"
required: true
type: "string"
Additionally you may want an authorizer if you're at all worried about DDoS or serving up secure data.此外,如果您完全担心 DDoS 或提供安全数据,您可能需要授权方。 That's done by adding a
security
array as a sibling to parameters, and a securityDefinitions
block as a sibling to paths
这是通过添加一个
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",
}
*note I'm publishing swagger as a terraform template, hence the ${}
substitution. *注意我将 swagger 作为 terraform 模板发布,因此
${}
替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.