This project provides an API gateway in front of other Democracy Club APIs.
/postcode
and /address
APIs provide a nice abstraction over calling
both the WDIV and WCIVF APIs and combine the responses./elections
endpoint is a straight proxy for EE's /elections
endpoint.cp aggregator-api/aggregator/settings/local.example.py aggregator-api/aggregator/settings/local.py
Install Python dependencies
pipenv install
no longer works, and instead we must install by category. pipenv install --categories "frontend api dev-packages"
will get you everything.pipenv install --categories "frontend" django
pipenv uninstall --categories "frontend" django
Run the test suite: pytest
Run lint checks: pytest --ruff
Auto-format: ruff format .
TODO: Update this
For local development, the only required setting is SECRET_KEY
. In local.py
,
it may also be useful to set:
EE_BASE_URL
- e.g: to run against a local WDIV install instead of
elections.democracyclub.org.ukWCIVF_BASE_URL
- e.g: to run against a local WDIV install instead of
whocanivotefor.co.ukWDIV_BASE_URL
- e.g: to run against a local WDIV install instead of
wheredoivote.co.ukWDIV_API_KEY
- WDIV API key. In local dev, anonymous access is generally
sufficient. You are unlikely to exceed the rate limit.In production, settings are obtained from environment variables. In production, we need:
SECRET_KEY
- Django secret key.WDIV_API_KEY
- WDIV API key. For production usage, we must call WDIV with an
API key to ensure we are not rate limited.SENTRY_DSN
- If set, exceptions will be logged here.ENV
- "prod" or "dev" - used by and sentry. FIXME: not currently propagated
via the SAM CLIdevelopment
and staging
in parallelproduction
, if staging
smoke tests passDevelopment deployments are described in detail in a separate document.
Here are the happy-path steps to create a deployment in DC's development AWS account.
Before following these steps:
<NAME>
NEW_ENV_NAME=<NAME> python samconfig.toml.d/new-dev-env.py >>samconfig.toml
AWS_DEFAULT_REGION=eu-west-2 pipenv run sam validate
make all
sam build --config-env <NAME> --use-container --cached
sam deploy --config-env <NAME>
These steps should have deployed the app to Lambda, accessible via AWS API Gateway on the 'AggregatorApiFqdn' domain mentioned near the end of the deployment output, but only when accessed the path '/Prod'.
You can continue and add TLS, caching, and a custom domain to this deployment by following the rest of the deployment document.