Aws lambda proxy Swagger template integration

元气小坏坏 提交于 2021-01-27 14:32:24

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/56040691/aws-lambda-proxy-swagger-template-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!