在aws api网关内自动配置flaskapi rest应用程序的包。

ct-api-gateway-deployer的Python项目详细描述


ct api网关部署程序

这个项目的目的是在aws api网关服务中自动化api的部署。

此外,它还提供了一个helper类来构建flask api rest应用程序。

工作原理

项目中提供的python包需要两个配置文件:

  • 一个带有AWS配置的文件,用于访问和部署API网关服务中的API路由
  • 其他带有要部署的api路由的文件。

在命令行中执行项目可执行文件时,它将读取routes文件,以构建一个OpenAPIjson对象,并将AWS specifications导入api网关。

在进程中创建的openapi配置保存为yml文件,可以在命令行中进行配置,以便在进程完成运行后保存并存储在磁盘中。

使用yml文件,进程将访问aws并将openapi配置上载到api网关。

此外,这个包还提供了FlaskTools class,允许使用相同的路由文件构建Flask REST API应用程序。

安装

python包可以使用 pip命令:

pip install ct-api-gateway-deployer

用法

基本用法

python ct_api_gateway_deployer --aws-config=aws.config.json--routes=routes.json

命令行选项

可以使用控制台帮助程序显示这些选项:

python ct_api_gateway_deployer --help

Command optionRequiredDescription
--aws-config=stringTrueRefers to the file's path with the configurations to access the AWS's services and create the API Gateway.
--routes=stringTrueRefers to the file's path with the API's routes configurations to be deployed.
--keep-output-openapifile=booleanFalseBoolan flag to keep the OpenAPI file generated during the deployment process. By default, the file is erased in the end of the process.
--output-openapifile-path=stringFalseRefers the path where will be write the OpenAPI file to be deployed in the API Gateway. By default, will create the file "swagger.yml" in the root path where the command was executed.
-h, --helpFalseShow help message.

Amazon Web Services File Configuration

--aws config命令选项需要一个JSON文件,该文件指定访问aws环境的配置对象json对象遵循如下结构:

{"region":"","aws":{"access_key_id":"","secret_access_key":""},"apiGateway":{"name":"","rest_api_id":"","baseEndpointURL":"","stage":"","basePath":""}}

其中:

  • 基本对象
AttributeTypeDescription
regionstringAWS region identifier where the API Gateway will be deployed.
awsaws attributeAWS access configurations.
apiGatewayapiGateway attributeAWS API Gateway configurations where the API will be deployed.
^{tb 3}$ ^{tb 4}$

API Routes File Configuration

--routes命令选项需要一个json文件,该文件指定配置api的路由和配置。JSON对象的某些属性将直接配置--aws config中指定的API网关环境;另外,其他属性将用于通过包中提供的FlaskTools类配置Flask REST API

json对象遵循以下结构:

{"blueprint":{"name":"","url_prefix":"","resources":[{"name":"","flask":{"resourceModule":"","resourceClass":"","strictSlashes":false},"methods":[{"path":"","cors":{"enable":true,"removeDefaultResponseTemplates":true,"allowHeaders":[""]},"queryParams":[{"name":"","type":""}],"actions":[{"type":"","integration":"","proxyIntegration":true,"vpcLink":"","authorization":""}]}]}]}}

其中:

  • 基本对象
AttributeTypeDescription
blueprintblueprint attributeBlueprint configuration. The blueprint concept is explained in: http://flask.pocoo.org/docs/1.0/blueprints/#blueprints.
^{tb 6}$ ^{tb 7}$ ^{tb 8}$ ^{tb 9}$
AttributeTypeDescription
enablebooleanFlag to enable the CORS configuration.
removeDefaultResponseTemplatesbooleanFlag to remove the responseTemplate configuration. Used when the default HTTP application/json response is not wanted.
allowHeadersList of stringList of attributes allowed in the request header.
^{tb 11}$ ^{tb 12}$

FlaskTools class

The FlaskTools Python class can be imported in an Flask REST API project to create an blueprint with the resources routes specified in the routes file.

The method signature is:

^{pr 3}$

Where:

  • application: is a Flask object where the Blueprint that contains the resources and routes will be appended.
  • router_file_path: is the path to the JSON file with the routes' configurations.

Links

反馈

欢迎所有反馈。bug报告、功能请求、评论和其他内容可以直接发送到贡献者的电子邮件。

贡献者

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将值插入sql表的选定列。使用c等参数#   IF语句的java JList数据添加   java在这种情况下有没有更好的方法来调整哈希值?   java@Valid不会触发@Repository中的验证   java如何在安卓中调整位图的大小   iTextJava。lang.NoClassDefFoundError:com/itextpdf/text/DocumentException   java使用ResourceBundleMessageSource加载一个ressource包(message.properties)的全部内容   java如何通过JasperReports 6动态设置Excel工作表名称。十、   java是编写这个程序的最佳方式   JAVA伊奥。FileNotFoundException:C:\Program Files\Apache软件基金会\Tomcat 8.0\。。\webapps\ROOT\\u cips\config。伊尼   java我正在尝试创建一个TictaToe程序,但是JOptionPane和绘图有问题   垃圾收集为什么java中的finalize()方法不在Finalizer类中?为什么它是在对象类中定义的?   java如何用括号编码替换url中的括号?   java web集成移动应用程序   在netbeans中运行MIDP2应用程序时出现java错误