A test driven micro-service template to build and deploy a fast API service with Docker and on API Gateway / AWS Lambda.
This template also includes auto admin capabilities for models.
Check out the live site.
-
Python
requirements.txt
- linting and testing:
pre-commit
pytest test
-
Docker is used to run locally and in the cloud.
Dockerfile
Dockerfile with multi-architecture supportdocker-compose
API Gateway and Lambda functions built from docker image
-
API sample routes are mapped to:
GET /
GET /resources
POST /resources
PUT /resources/{:id}
DELETE /resources/{:id}
-
GET /tasks
POST /tasks
PUT /tasks/{:id}
DELETE /tasks/{:id}
-
Admin routes are mapped to:
GET /admin/
GET /admin/{:resource}
GET /admin/{:resource}/{:id}
-
Serverless API Gateway and functions mapped to lambda-web on cloud (HttpServer locally).
-
Deployment Actions to deploy on branch commits
- .github/workflows Github actions
- lint [
feature
] - test [
feature
] - deploy [
main
,production
] - tag [
production
]
- lint [
- .github/workflows Github actions
-
Views Bootstrap 5 views based of the following templates
- templates Github actions
├── apps
├── api
├── models
├── routes
├── services
├── views
├── tests
├── integration
├── unit
├── templates
├── accounts
├── admin
├── includes
├── layout
├── layout
├── static
├── assets
├── .github
├── workflows
Create a new service by selecting the button above 👇
To setup your local environment:
python -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
While working on a feature to start the service locally run:
python apps/main.py
Or use docker
docker-compose up
docker-compose up --build
Before you are ready to merge your feature, to test running lamnbda, you can run:
serverless offline
For CRUD applications, follow the example in resource.rs and add your resource route to:
apps/api/routes
For example if you are building an API to manage Users and Shares, you would create:
apps/api/routes/users.rs
apps/api/routes/shares.rs
For admin enabled views, inherit from
BaseAdmin
. Follow the example resource.rs add your models:
apps/api/models/users.rs
apps/api/models/shares.rs
TODO: Add DB support
Follow the example resource/dashboard.html for a custom model view:
Before writing any functionality, we recommend you write your tests first. See the examples in:
To add tests, simply add to the appropriate package and using automod it will be automatically detected to run.
To run tests
pytest test
To run specific tests
pytest test --package <package-name>
** When using actix-web modules, it is not recommended (or easy) to unit test a route module. Follow the example in tests/integration/routes/resource.rs to add an route integration test.
aws configure
has been run.
To deploy locally:
npm install
serverless deploy
Github workflows are will trigger of off specific branches
- feature.yml: Lint and test worflows will run any time there is a push to any feature branch.
- development.yml: Lint, test and deployment worflows will run any time there is a push to main branch.
- production.yml: Lint, test, deployment and release worflows will run any time there is a push to main branch.
This project uses Github workflows.
You will need to configure a role in AWS for the github service to use. Follow the instructions here.
You may need to add more permissions to your role. Be as restrictive as possible when adding more permissions
If you have additions, changes, fixes, create a Pull Request and tag any reviewers and it will be reviewed promptly.
If you are having issues, create an issue and we will investigate.