简体   繁体   English

如何为 aws-lambda python API 生成 swagger 文档?

[英]How to generate swagger documentation for aws-lambda python API?

I have an AWS-lambda based API, written in python.我有一个基于 AWS-lambda 的 API,用 python 编写。 The data is in elastic search.数据在弹性搜索中。 The python code is basically an interface between the user and ES. python代码基本上是用户和ES之间的接口。

I need to add swagger documentation.我需要添加 swagger 文档。

I can create the swagger.json file manually, but I would like to have some automated process, to be able to keep up with future changes.我可以手动创建 swagger.json 文件,但我希望有一些自动化过程,以便能够跟上未来的变化。

Is there a library that would help me to somehow automatically generate the swagger documentation?是否有一个库可以帮助我以某种方式自动生成 swagger 文档?

I was searching around, and I found multiple libraries for flask, but I'm not using flask我四处寻找,发现了多个烧瓶库,但我没有使用烧瓶

Steps to get swagger details from AWS API gateway :从 AWS API 网关获取 swagger 详细信息的步骤:

  1. Go to API gateway转到 API 网关
  2. Click on stage点击舞台
  3. Select Stage which you need to get选择需要获得的舞台
  4. Select "Export" tab选择“导出”选项卡
  5. Choose required option like Export as Swagger选择所需的选项,如导出为 Swagger

Swagger 导出图像

In API Gateway you can create REST APIs or HTTP APIs, for the differences see here .在 API Gateway 中,您可以创建 REST API 或 HTTP API,差异请参见此处

@aviboy2006's answer is for the older standard, REST API. @aviboy2006 的答案是针对较旧的标准 REST API。

If you are using the newer HTTP API, you can only export in OpenAPI 3.0 format (Swagger will import this, unless you have an old version) and you have to export using the AWS CLI:如果您使用较新的 HTTP API,则只能以 OpenAPI 3.0 格式导出(Swagger 将导入此格式,除非您有旧版本),并且必须使用 AWS CLI 导出:

aws apigatewayv2 export-api \
    --api-id api-id  \
    --output-type YAML  \
    --specification OAS30 \
    --stage-name prod \
    stage-definition.yaml

for output type you can choose between JSON and YAML .对于输出类型,您可以在JSONYAML之间进行选择。

Source: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-export.html来源: https : //docs.aws.amazon.com/apigateway/latest/developerguide/http-api-export.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 AWS-Lambda(Python) 中,我如何调用需要在 header 中进行令牌授权的外部 API - In AWS-Lambda(Python), how can I Invoke External API which needs Token Authorization in the header AWS-Lambda:如何在 python 中处理 SNS 事件 - AWS-Lambda: How to deal with SNS event in python Python aws-lambda返回xml文件到aws-api-gateway - Python aws-lambda return xml file to aws-api-gateway 使用 Exec 或 Eval 在 AWS-LAMBDA 中运行不受信任的 Python 代码 - Running Untrusted Python Code in AWS-LAMBDA using Exec or Eval aws-lambda-python教程指的是'virtualenv'和'source' - aws-lambda - python tutorial refers to 'virtualenv' and 'source' pycripto和AWS-Lambda错误 - Error with pycripto and AWS-Lambda 如何使用 boto3 和 Docker 部署 AWS-Lambda? - How to deploy AWS-Lambda with boto3 and Docker? aws-lambda 函数中的异常处理 - Exception handling in aws-lambda functions OSError:[Errno 2]没有这样的文件或目录:php shell_exec [AWS-Lambda]内部的[python脚本] - OSError: [Errno 2] No such file or directory : [python script] inside php shell_exec [ AWS-Lambda] 从 aws-lambda 导入 pysftp 时如何修复导入错误“No module named '_cffi_backend'” - How to fix import error "No module named '_cffi_backend' " when import pysftp from aws-lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM