Helper functions to run Django and Flask applications in AWS Copilot/ECS.
Project description
DBT Copilot Python
A set of utility functions for running Django & Flask apps in AWS ECS via AWS Copilot.
Using dbt-copilot-python
Installation
pip install dbt-copilot-python
Usage
ALLOWED_HOSTS setting
Add the ECS container IP to ALLOWED_HOSTS setting so that the Application Load Balancer (ALB) healthcheck will succeed:
from dbt_copilot_python.network import setup_allowed_hosts
ALLOWED_HOSTS = [...]
ALLOWED_HOSTS = setup_allowed_hosts(ALLOWED_HOSTS)
Celery health check
Add the health check in your application's Celery config file...
from dbt_copilot_python.celery_health_check import healthcheck
celery_app = Celery("application_name")
...
celery_app = healthcheck.setup(celery_app)
Add the health check to the Celery worker service in docker-compose.yml...
healthcheck:
test: [ "CMD-SHELL", "python -m dbt_copilot_python.celery_health_check.healthcheck" ]
interval: 10s
timeout: 5s
retries: 2
start_period: 5s
In your *-deploy codebase, add the health check to the Celery worker service in copilot/celery-worker/manifest.yml...
healthcheck:
command: [ "CMD-SHELL", "launcher bash -c 'python -m dbt_copilot_python.celery_health_check.healthcheck'" ]
interval: 10s
timeout: 5s
retries: 2
start_period: 10s
DATABASES setting
To configure the DATABASES setting from an RDS JSON object stored in AWS Secrets Manager, there are two options.
-
Configure the
DATABASESsetting to use a database URL (recommended):Note: This is dependent on the
dj-database-urlpackage which can be installed viapip install dj-database-url.import dj_database_url from dbt_copilot_python.database import database_url_from_env DATABASES = { "default": dj_database_url.config( default=database_url_from_env("DATABASE_ENV_VAR_KEY") ) }
-
Configure the
DATABASESsetting to use a dictionary containing the settings:from dbt-copilot-python.database import database_from_env DATABASES = database_from_env("DATABASE_ENV_VAR_KEY")
Contributing to dbt-copilot-python
Requirements
- Poetry;
pip install poetry
Install dependencies & pre-commit hooks
poetry install && poetry run pre-commit install
Run the tests
poetry run pytest
Publishing
To publish the Python package dbt-copilot-python, you will need an API token.
- Acquire API token from Passman.
- Request access from the SRE team.
- Note: You will need access to the
platformgroup in Passman.
- Run
poetry config pypi-token.pypi <token>to add the token to your Poetry configuration.
Update the version, as the same version cannot be published to PyPi.
poetry version patch
More options for the version command can be found in the Poetry documentation. For example, for a minor version bump: poetry version minor.
Build the Python package.
poetry build
Publish the Python package.
Note: Make sure your Pull Request (PR) is approved and contains the version upgrade in pyproject.toml before publishing the package.
poetry publish
Check the PyPi Release history to make sure the package has been updated.
For an optional manual check, install the package locally and test everything works as expected.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_copilot_python-0.1.5.dev5.tar.gz.
File metadata
- Download URL: dbt_copilot_python-0.1.5.dev5.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.11.5 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
788e8eef6c48d652a3b90f78e6ecc8e95e8e57122309edde395a1bca7272d004
|
|
| MD5 |
ee7814ee876f34c5a6f6177a8bb500eb
|
|
| BLAKE2b-256 |
1a210b647eb8e06a42f87dc1f58b96b163a6058f38d167dfdf1c6f6e4beb4fbc
|
File details
Details for the file dbt_copilot_python-0.1.5.dev5-py3-none-any.whl.
File metadata
- Download URL: dbt_copilot_python-0.1.5.dev5-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.11.5 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a01428582bc6d1a2b4db0e1f3e445c091fb13826e96f5079c552c0af4cb7c29
|
|
| MD5 |
aa31de51db5d379ac162533e745160dd
|
|
| BLAKE2b-256 |
eb0c67613ac9ebc4e0fb88f7e6b0c0a94b2c7917b145df50b272f9fe940be9cb
|