Package: ct-api-gateway-deployer
ct-api-gateway-deployerThis project aims to automatizate the deployment of an API inside the AWS API Gateway service.Also, it provides a helper class to build a Flask API Rest application.How it worksThe Python package provided in the project will require two configurations files:One file with the AWS configurations to access and deploy the API routes in the API Gateway service;Other file with the API routes to be deployed.When the project executable is executed in the command line, it will read the routes file to build anOpenAPIJSON object with theAWS specificationsto be imported in the API Gateway.The OpenAPI configuration created in the process is save as an YML file, that can be configured in the command line to be keep and stored in the disk after the process finish to run.With the YML file, the process will access the AWS and upload the OpenAPI configuration to the API Gateway.Also, this package provides theFlaskTools class, that allows build anFlask REST APIapplication using the same routes file.InstallingThe Python package can be installing using thepipcommand:pip install ct-api-gateway-deployerUsageBasic usagepython ct_api_gateway_deployer--aws-config=aws.config.json--routes=routes.jsonCommand line optionsThe options can be showed using the console helper:python ct_api_gateway_deployer --helpCommand 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 ConfigurationThe--aws-configcommand option requires a JSON file that specify the configuration object to access the AWS environment. The JSON objects follows the bellow structure:{"region":"","aws":{"access_key_id":"","secret_access_key":""},"apiGateway":{"name":"","rest_api_id":"","baseEndpointURL":"","stage":"","basePath":""}}Where:Basic objectAttributeTypeDescriptionregionstringAWS region identifier where the API Gateway will be deployed.awsawsattributeAWS access configurations.apiGatewayapiGatewayattributeAWS API Gateway configurations where the API will be deployed.awsattributeAttributeTypeDescriptionaccess_key_idstringAWS access keyused to communicate with the API Gateway service.secret_access_keystringAWS secret access keyused to communicate with the API Gateway service.apiGatewayattributeAttributeTypeDescriptionnamestringAWS API Gateway name.rest_api_idstringAWS API Gateway identifier.stagestringAWS API Gateway stage where the API will be deployed.baseEndpointURLstringDefault endpoint for the API resources. Is overwritten by theurl_prefix; configured in the routes files.basePathstringDefault suffix path for the base endpoint. Is overwritten by the stage when the API is deployed by the API Gateway.API Routes File ConfigurationThe--routescommand option requires a JSON file that specify the configuration API's routes and configuration. Some attributes of the JSON object will configure directly the API Gateway environment specified in the--aws-config; also, other attributes, will be used to configure a Flask REST API through the FlaskTools class provided in the package.The JSON object follows the bellow structure:{"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":""}]}]}]}}Where:Basic objectAttributeTypeDescriptionblueprintblueprintattributeBlueprint configuration. The blueprint concept is explained in:http://flask.pocoo.org/docs/1.0/blueprints/#blueprints.blueprintattributeAttributeTypeDescriptionnamestringBlueprint's name.url_prefixstringBlueprint's default url prefix for the API resources.resourcesList ofresourceattributeThe list of resources provided by blueprint in the API.resourceattributeAttributeTypeDescriptionnamestringThe resource's name.flaskflaskattributeThe Flask's configurations that will be used by theFlaskTools class.methodsList ofmethodattributeThe list of methods that will be allowed for the parent resource.flaskattributeAttributeTypeDescriptionresourceModulestringModule where the Flask resource class is available.resourceClassstringNome of the Flask class that implementsflask_restful.Resource.strictSlashesbooleanBoolean flag to ignore the slash character (/) at the end of the in Flask route.methodattributeAttributeTypeDescriptionpathstringPath to the method endpoint.corscorsattributeConfigurations forCORSin the API Gateway.queryParamsList ofqueryParamsattributeParameters in the routes query.actionsList ofactionattributeList of HTTP actions allowed in the method.corsattributeAttributeTypeDescriptionenablebooleanFlag to enable theCORSconfiguration.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.queryParamsattributeAttributeTypeDescriptionnamestringName of the parameter.typestringType of the parameter. Used in the parse for the route in the Flask REST API resource class.actionattributeAttributeTypeDescriptiontypestringConstant to identify the HTTP request action. Choose one from: GET or POST or PUT or DELETE.integrationstringThe integration connection type used in the API Gateway. Choose one from: VPC_LINK or INTERNET.proxyIntegrationbooleanFlag to enable the integration of the received request on the API Gateway be replicated in the HTTP backend.vpcLinkstringAWS VPC identifier. Just use when theintegrationparameter is configured as VPC_LINK; otherwise, set asnull.authorizationstringAdds verification for authorization headers. Choose from: AWS_IAM or null.FlaskTools classThe FlaskTools Python class can be imported in an Flask REST API project to create an blueprint with the resources routes specified in theroutesfile.The method signature is:fromflaskimportFlaskclassFlaskTools:@staticmethoddefadd_resources(application:Flask,router_file_path:str)->NoneWhere: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.LinksPypi repository:https://pypi.org/project/ct-api-gateway-deployer/Pypi Test repository:https://test.pypi.org/project/ct-api-gateway-deployer/Source code repository:https://bitbucket.org/cinnecta/ct_api_gateway_deployerFeedbackEvery feedback is welcome. Bugs reports, feature request, comments and others can be send directly to the contributors' email.ContributorsEduardo Manoel (Business email)[2019]