This project was an attempt to familiarize myself with Terraform and Ansible for data pipeline use cases, as well as solve a personal need for a weight tracking and analytics mechanism with better visualization capabilities than Google Sheets, but not tied to a commercial health platform.
- psql
- terraform
- ansible
- dbt
- python3
- AWS RDS and EC2
- Hex
Creates Postgres RDS instance and Ubuntu EC2 instance needed for scheduled load and transform
- Update variables as needed in
variables.tfandterraform.tfvars, removingTEMPLATEfrom the filename terraform initif new cloneterraform planand verifyterraform apply
- Update repos -
sudo apt update - Install Git -
sudo apt install git - Install pip -
sudo apt install python3-pip - Install venv -
sudo apt install python3.8-venv - Create
logdirectory in home directory for run logs -mkdir -p ~/log - Clone git repo in home directory
- Create venv in repo -
cd fitness-tracker-pipeline && python3 -m venv dbt-venv - Activate venv -
source dbt-venv/bin/activate - Install dbt -
python -m pip install dbt-postgres - Update (if needed) and verify dbt profiles.yml -
cd dbt_fit && dbt debug --profiles-dir=profiles - Install load script requirements -
cd load && python -m pip install -r requirements.txt - Ensure git doesn't read changed permissions as a new file -
git config core.fileMode falseSee here. - Make run script executable -
cd infra/scripts && sudo chmod u+x run.sh - Create cron job and input healthchecks.io UUID:
0 6 * * * /home/ubuntu/fitness-tracker-pipeline/infra/scripts/run.sh && curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/UUID
- Add host to
inventory.yaml - Update remote_user in
config_transform_ec2.yamlif needed - Run
ansible-playbook -i inventory.yaml config_transform_ec2.yaml --key-file "KEY PATH"referencing path to AWS .pem key - SSH in to instance to update dbt project and verify connection:
dbt debug --profiles-dir=profiles - Create cron job for run and update healthchecks.io monitoring UUID:
0 6 * * * /home/ubuntu/fitness-tracker-pipeline/infra/scripts/run.sh && curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/UUID
Create raw__weight_daily table in RDS:
psql --host=RDS-INSTANCE --port=5432 --username=USER --password --dbname=DB -f infra/db_init/create_raw.sql
psql --host=RDS-INSTANCE --port=5432 --username=USER --password --dbname=DB -f load/load.sql
Weight is input daily on my local machine with sh load/data_log.sh ARG where the argument is my daily weight.
Extract and load is triggered manually on local machine following data input step. python3 load/data_load.py parses db info and data location from config.yaml, extracts dataframe from raw data file, and inserts into raw schema table in RDS Postgres.
Originally, I was inputting data into a Google Sheet and intended to load that automatically into RDS. Unfortunately, I am deprecating this method as Google makes auth against a private sheet too cumbersome to manage.
Transformation via dbt is run daily at 0600 UTC on an EC2 instance. Monitoring is configured via healthchecks.io. Simple logging is configured as part of the run script.
The run script triggers a git pull and activates the venv to trigger a dbt snapshot, run, and test. Outputs are logged and logs are automatically deleted after 14d.
- Date Spine - simple date spine of date components for easier date aggregation
- Weight by Day - join on date spine for weight by day
- Weight by Week - join on date spine to avg weight per week
- Weight by Month - join on date spine to avg weight per month
Hex.tech is being using for BI and analytics. It is necessary to add the following Hex IPs to the Terraform ingress whitelist
3.129.36.245
3.13.16.99
3.18.79.139