Serverless application with CI/CD based on AWS and Bitbucket Pipelines
Creating an application skeleton
The project is a typical Django application. The only difference is that the application settings will be pulled through environment variables. The project repository is located on Bitbucket.
There are two sets of requirements — basic and test. Basic requirements:
It is typical for a project with Django, REST API and PostgreSQL as database. Let’s add params to Django settings parameters that are being injected through environment variables:
Zappa is a framework that simplifies the deployment of a WSGI application based on API Gateway and Lambda . It provides abilities to generate Cloudformation template and convert Lambda’s event to WSGI request, which allows you to use the classic application scheme. Then add the dependencies for the tests and linters
and their configuration files.
It is either JSON or YAML file with a set of variables. In my version it is stored on a hidden S3 bucket in the settings of repository and and is being copied each time when creating a new artifact.
Everything that relates to the project settings is written in environment_variables and can be found in the Zappa documentation.
Bitbucket Pipelines configuration
For CI / CD, I use the following shell script ci.sh:
The script works in a typical Bitbucket Pipeline container (image: python: 3.6.1) on Debian. The pipeline allows you to use any container with DockerHub.
Sample configurations of bibucket_pipelines.yml:
The project is released by tags, the master branch is installed in the dev1 environment.
Therefore, you should enable Bitbucket Pipelines and set up environment variables:
That’s all, keep calm and start developing.
Behind the scenes, there is the topic of secrets encryption and Cloudfront usage, as well as RDS, ACM, IAM, Route53 settings, etc. Those, who are interested, can find all this in the AWS documentation.