Lambda代理Swagger模板集成

Lambda代理Swagger模板集成

本文介绍了AWS Lambda代理Swagger模板集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置swagger模板以一次调用全部代码.

让我们说在processlambda下面有两个功能".这是正确的openapi 3.0模板,还是我必须专门配置请求类型和响应类型

  {"openapi":"3.0.0",信息":{"version":"2016-09-12T17:50:37Z","title":"ProxyIntegrationWithLambda"},路径":{"/GetItemById":{"x-amazon-apigateway-any-method":{参数": [{"name":"proxy","in":路径",必填":是的,模式":{"type":字符串"}}],响应":{},"x-amazon-apigateway-integration":{响应":{默认": {"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":{参数": [{"name":"proxy","in":路径",必填":是的,模式":{"type":字符串"}}],响应":{},"x-amazon-apigateway-integration":{响应":{默认": {"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"}}}},服务器":[{"url":"https://gy415nuibc.execute-api.us-east-1.amazonaws.com/{basePath}",变量":{"basePath":{默认":"/处理"}}}]} 

尚未对此进行测试,但是C#函数代码使用API​​Gateway响应/请求标准arts对象

解决方案

或者,您可以使用的一个好方法是配置API网关(指向AWS Lambda),然后配置生成 API网关配置中的openapi规范,然后生成您的c#客户端.

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

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

  aws apoigateway get-export--rest-api-id'idfromapigateway-grab-inside-awsdashboard'--stage-namem'stage-grab-inside-awsdashboard'--export-type'swagger'输出文件,带有openapispec生成的step1.json 

第2步,共2步)生成客户端,例如:

  nswag swagger2csclient/input:outputfile-with-openapispec-produced-step1.json/类名:SpecifyYourCSharpClassName/namespace:SpecifyYourCSharpNamespace/输出:SpecifyYourCSharpFile 

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

I'm trying to setup swagger template to call my all in one lambda.

lets say there are two "functions" underneath processlambda.Would this be a correct openapi 3.0 template, or do I have to specifically configure request types and response types

{
   "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"
            }
         }
      }
   ]
}

haven't tested this yet, but C# function code uses APIGateway response/request standart aws objects

解决方案

As an alternative, a good path you may use is to configure your API Gateway(pointing to AWS Lambda) and then generate your openapi specs from API Gateway config and then generate your c# clients.

After API Gateway is configured you can run the following steps:

Step 1 of 2) run get-export , example :

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

Step 2 of 2) Generate client, example:

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

The result of step 2 generates c# classes that can be used in integration testing.

这篇关于AWS Lambda代理Swagger模板集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:12