【问题标题】:Aws lambda proxy Swagger template integrationAws lambda 代理 Swagger 模板集成
【发布时间】:2019-09-26 04:25:32
【问题描述】:

我正在尝试设置 swagger 模板以在一个 lambda 中调用我的全部。

可以说在 processlambda 下有两个“函数”。 这是一个正确的 openapi 3.0 模板,还是我必须专门配置请求类型和响应类型

{
   "openapi": "3.0.0",
   "info": {
      "version": "2016-09-12T17:50:37Z",
      "title": "ProxyIntegrationWithLambda"
   },
   "paths": {
      "/GetItemById": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "POST",
               "cacheNamespace": "roq9wj",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "aws_proxy"
            }
         }
      }
   },
      "/SaveItem": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "POST",
               "cacheNamespace": "roq9wj",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "aws_proxy"
            }
         }
      }
   },
   "servers": [
      {
         "url": "https://gy415nuibc.execute-api.us-east-1.amazonaws.com/{basePath}",
         "variables": {
            "basePath": {
              "default": "/Process"
            }
         }
      }
   ]
}

尚未对此进行测试,但 C# 函数代码使用 APIGateway 响应/请求标准 aws 对象

【问题讨论】:

    标签: c# amazon-web-services aws-lambda openapi


    【解决方案1】:

    作为替代方案,您可以使用的一个好方法是配置您的 API Gateway(指向 AWS Lambda),然后从 API Gateway 配置 generate 您的 openapi 规范,然后 generate 您的 c# 客户端。

    配置 API Gateway 后,您可以运行以下步骤:

    第 1 步,共 2 步)运行 get-export,例如:

    aws apoigateway get-export 
      --rest-api-id 'idfromapigateway-grab-inside-awsdashboard' 
      --stage-namem 'stage-grab-inside-awsdashboard' 
      --export-type 'swagger' outputfile-with-openapispec-generated-step1.json
    

    第 2 步,共 2) Generate 客户端,示例:

    nswag swagger2csclient /input:outputfile-with-openapispec-generated-step1.json
      /classname:SpecifyYourCSharpClassName
      /namespace:SpecifyYourCSharpNamespace
      /output:SpecifyYourCSharpFile
    

    第 2 步的结果生成可用于集成测试的 c# 类。

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      • 2018-05-04
      相关资源
      最近更新 更多