AWS lambda 代理 Swagger 模板集成
Aws lambda proxy Swagger template integration
我正在尝试设置 swagger 模板来调用我的 all in one 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 response/request 标准 aws 对象
作为替代方案,您可以使用的一个好方法是配置您的 API 网关(指向 AWS Lambda)然后 generate your openapi specs from API Gateway config and then 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# 类。
我正在尝试设置 swagger 模板来调用我的 all in one 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 response/request 标准 aws 对象
作为替代方案,您可以使用的一个好方法是配置您的 API 网关(指向 AWS Lambda)然后 generate your openapi specs from API Gateway config and then 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# 类。