AWS Api-Gateway Lambda代理端点的Swagger定义

问题描述 投票:1回答:1

FYI-我已经检查了与此相关的类似问题,但没有一个能解决我的问题。

我正在尝试为AWS Api-Gateway下的许多API创建Swagger定义。我能够从我从API Stage下载的自动生成的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"

这与AWS文档一致:enter link description here

请,我想念什么?

amazon-web-services swagger documentation aws-api-gateway api-gateway
1个回答
0
投票

乍一看,我相信您在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",
    }

*注意,我正在以表格形式模板发布招摇,因此是${}替代。

© www.soinside.com 2019 - 2024. All rights reserved.