serverless-enterprise-application-boilerplate-for-python
serverless-enterprise-application-boilerplate-for-python copied to clipboard
A boilerplate to build an AWS serverless enterprise application for Python
Serverless Enterprise Application Boilerplate For Python
This is a boilerplate to build an AWS serverless enterprise application. In general, a serverless application is composed of some CloudFormation stacks. This repository shows you all the things which build that like how to separate each stack and build a directory structure using Serverless Framework, Python, and CircleCI.
Deploy image
Deploy this app to AWS using Serverless Framework via CircleCI.
Directory Structure
| Directory | Description |
|---|---|
| layer | Lambda layers. Put Python external libraries and common libraries that can use each service. |
| lib | Common libraries that can use each service. |
| services/api | API Service which a part of this application. Here is the architecture |
| services/workflow | API Service which a part of this application. Here is the architecture |
| services/message-service | Message Service which a part of this application. Here is the architecture |
| services/stream-service | Stream Service which a part of this application. Here is the architecture |
| tests/unit_tests | Put unit tests. |
| tests/integration_tests | Put E2E tests. |
Commands
All commands you need to build this application is defined as yarn script. Here is a part of that.
| Command | Description |
|---|---|
| yarn lint | Run lint with flake8. |
| yarn test:unit | Run unit testing. |
| yarn test:workflow | Run E2E testing for workflow service. |
| yarn deploy:workflow | Deploy workflow service. |
| yarn deploy:db | Deploy tables. |
All commands are defined in package.json. See that.
Setup
You can use this boilerplate as a skeleton to build your serverless application. First, check out the code and remove .git directory so that you can put it in your repository.
$ git clone [email protected]:serverless-operations/serverless-enterprise-application-boilerplate-for-python.git
$ cd serverless-enterprise-application-boilerplate-for-python
$ rm -rf .git
$ yarn install
Setup needed environment valiables via direnv.
$ cp -pr .envrc.sample .envrc
$ vi .envrc # edit
# allow
$ direnv allow
Install Python external libraries to develop into venv.
$ python3 -m venv venv
$ . venv/bin/activate
$ pip3 install -r requirements-dev.txt
Create a deployment S3 bucket to your AWS account with following schema. There valiables are defined in serverless-common.yml
<appname>.<deploymentBucketPath(stage)>.<region>.deploys
Run deploy API to see this setup successfully.
$ yarn deploy:api
AWS Account
This boilerplate supposes to use two AWS accounts, which are for production and other than that. You can switch AWS accounts to deploy using the CircleCI context feature.