在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 option | Required | Description |
---|---|---|
--aws-config=string | True | Refers to the file's path with the configurations to access the AWS's services and create the API Gateway. |
--routes=string | True | Refers to the file's path with the API's routes configurations to be deployed. |
--keep-output-openapifile=boolean | False | Boolan 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=string | False | Refers 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, --help | False | Show 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":""}}
其中:
- 基本对象
Attribute | Type | Description |
---|---|---|
region | string | AWS region identifier where the API Gateway will be deployed. |
aws | aws attribute | AWS access configurations. |
apiGateway | apiGateway attribute | AWS API Gateway configurations where the API will be deployed. |
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":""}]}]}]}}
其中:
- 基本对象
Attribute | Type | Description |
---|---|---|
blueprint | blueprint attribute | Blueprint configuration. The blueprint concept is explained in: http://flask.pocoo.org/docs/1.0/blueprints/#blueprints. |
Attribute | Type | Description |
---|---|---|
enable | boolean | Flag to enable the CORS configuration. |
removeDefaultResponseTemplates | boolean | Flag to remove the responseTemplate configuration. Used when the default HTTP application/json response is not wanted. |
allowHeaders | List of string | List of attributes allowed in the request header. |
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
- Pypi repository:https://pypi.org/project/ct-api-gateway-deployer/
- Pypi测试存储库:https://test.pypi.org/project/ct-api-gateway-deployer/
- 源代码存储库:https://bitbucket.org/cinnecta/ct_api_gateway_deployer
反馈
欢迎所有反馈。bug报告、功能请求、评论和其他内容可以直接发送到贡献者的电子邮件。
贡献者
- 爱德华多·马诺埃尔(Business email)[2019]