gpt4 book ai didi

c# - AWS lambda 代理 Swagger 模板集成

转载 作者:行者123 更新时间:2023-11-30 16:38:06 27 4
gpt4 key购买 nike

我正在尝试设置 swagger 模板来调用我的 all in one 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 对象

最佳答案

作为替代方案,您可以使用的一个好方法是配置您的 API 网关(指向 AWS Lambda)然后 generate API Gateway 配置中的 openapi 规范,然后是 generate你的 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' 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# 类。

关于c# - AWS lambda 代理 Swagger 模板集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56040691/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com