AWS Lambda代理Swagger模板集成

3
我正在尝试设置Swagger模板来调用我的一体化Lambda函数。
假设在processlambda下有两个"functions"。 这是否是正确的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对象。

1个回答

2
作为替代方案,您可以使用的一个好路径是配置API Gateway(指向AWS Lambda),然后从API Gateway配置生成您的openapi规范,然后生成您的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 of 2):生成客户端,例如:
nswag swagger2csclient /input:outputfile-with-openapispec-generated-step1.json
  /classname:SpecifyYourCSharpClassName
  /namespace:SpecifyYourCSharpNamespace
  /output:SpecifyYourCSharpFile

第二步的结果会生成 C# 类,可用于集成测试。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接