AWS Lambda代理Swagger模板集成

编程入门 行业动态 更新时间:2024-10-22 21:22:20
本文介绍了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":"gy415nuibc.execute-api.us-east-1.amazonaws/{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": "gy415nuibc.execute-api.us-east-1.amazonaws/{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模板集成

本文发布于:2023-11-24 04:26:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   AWS   Lambda   Swagger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!