This project involves building an ETL pipeline for a music streaming startup. The datasets provided include song data and log data, both stored in Amazon S3 buckets. The song dataset is a subset of the Million Song Dataset, containing JSON files with metadata about songs and their artists. The log dataset consists of JSON files generated by an event simulator, simulating app activity logs from the music streaming app.
The song dataset contains JSON files partitioned by the first three letters of each song's track ID. Each file provides metadata about a song and its corresponding artist.
The log dataset comprises JSON files partitioned by year and month, simulating app activity logs from the music streaming app. These logs include user interactions such as song plays.
The project employs a star schema with one fact table and multiple dimension tables:
songplays
: Records in log data associated with song plays (i.e., records with the page NextSong). Columns includesongplay_id
,start_time
,user_id
,level
,song_id
,artist_id
,session_id
,location
, anduser_agent
.
users
: Users in the app. Columns includeuser_id
,first_name
,last_name
,gender
, andlevel
.songs
: Songs in the music database. Columns includesong_id
,title
,artist_id
,year
, andduration
.artists
: Artists in the music database. Columns includeartist_id
,name
,location
,latitude
, andlongitude
.time
: Timestamps of records in songplays broken down into specific units. Columns includestart_time
,hour
,day
,week
,month
,year
, andweekday
.
create_table.py
: Creates fact and dimension tables as well as staging tables for the star schema in Redshift.etl.py
: Loads data from S3 into staging tables on Redshift and then processes that data into analytics tables on Redshift.sql_queries.py
: Defines SQL statements imported into other files.test.ipynb
: Creates a Redshift cluster, IAM role, and verifies the result after runningetl.py
.README.md
: Documentation providing insights into the project process and decisions for the ETL pipeline.
- Design schemas for fact and dimension tables.
- Write SQL CREATE statements for each table in
sql_queries.py
. - Complete logic in
create_tables.py
to connect to the database and create tables. - Write SQL DROP statements in
create_tables.py
to drop tables if they already exist, enabling resetting of the database for pipeline testing. - Launch a Redshift cluster and create an IAM role with S3 read access.
- Add Redshift database and IAM role info to
dwh.cfg
. - Test by running
create_tables.py
and checking table schemas in the Redshift database.
- Implement logic in
etl.py
to load data from S3 to staging tables on Redshift. - Implement logic in
etl.py
to load data from staging tables to analytics tables on Redshift. - Test by running
etl.py
after runningcreate_tables.py
and running analytic queries on Redshift database to compare results with expected results. - Delete the Redshift cluster when finished.
- Set environment variables
KEY
andSECRET
. - Choose
DB/DB_PASSWORD
indhw.cfg
. - Create IAM role, Redshift cluster, connect to S3 bucket, and configure TCP connectivity.
- Drop and recreate tables:
$ python create_tables.py
- Run the ETL pipeline:
$ python etl.py
- Delete IAM role and Redshift cluster.