A music streaming startup, Sparkify, has grown their user base and song database and want to move their processes and data onto the cloud. Their data resides in S3, in a directory of JSON logs on user activity on the app, as well as a directory with JSON metadata on the songs in their app.
They would like a data engineer to build an ETL pipeline that extract their data from S3, stage them in Redshift, and transform data into a set of dimensional tables for their Analytics team to continue finding insights into what songs their users are listening to. The objective of the project is to create a data warehouse on cloud (AWS Redshift) and build the ETL pipeline to prepare the data for the Analytics team.
In this project, the data engineer is required to build an ETL pipeline for a database hosted on Redshift. To complete the project, the data needs to be loaded from S3 to staging tables on Redshift and execute SQL statements that create the analytics tables from these staging tables.
We will be working with 2 datasets (Song Data & Log Data) in this project, that resides as json files in AWS S3.
The first dataset is a subset of real data from the Million Song Dataset. Each file is in JSON format and contains metadata about a song and the artist of that song. The files are partitioned by the first three letters of each song's track ID. For example, here are filepaths to two files in this dataset.
Below is an example of what a single song JSON file looks like:
{"num_songs": 1, "artist_id": "ARJIE2Y1187B994AB7", "artist_latitude": null, "artist_longitude": null, "artist_location": "", "artist_name": "Line Renaud", "song_id": "SOUPIRU12A6D4FA1E1", "title": "Der Kleine Dompfaff", "duration": 152.92036, "year": 0}
The second dataset consists of log files in JSON format generated by this event simulator based on the songs in the dataset above. These simulate app activity logs from an imaginary music streaming app based on configuration settings.
The log files in the dataset are partitioned by year and month.
The database schema consists of the following tables :
- staging_events
- staging_songs
- songplay_table - records in event data associated with song plays i.e. records with page NextSong - songplay_id, start_time, user_id, level, song_id, artist_id, session_id, location, user_agent
- user_table - users in the app - user_id, first_name, last_name, gender, level
- song_table - songs in music database - song_id, title, artist_id, year, duration
- artist_table - artists in music database - artist_id, name, location, lattitude, longitude
- time_table - timestamps of records in songplays broken down into specific units - start_time, hour, day, week, month, year, weekday
File / Folder | Description |
---|---|
static_resources | Folder at the root of the project, where static resources/images are present |
sql_queries.py | Contains the SQL queries for staging, schema definition and ETL |
create_tables.py | Drops and creates tables on AWS Redshift (Reset the tables) |
etl.py | Stages and transforms the data from S3 buckets and loads them into tables |
dwh.cfg | Sample configuration file for AWS |
README | Readme file |
- Create Table Schemas
- Design schemas for your fact and dimension tables
- Write a SQL CREATE statement for each of these tables in sql_queries.py
- Complete the logic in create_tables.py to connect to the database and create these tables
- Write SQL DROP statements to drop tables in the beginning of - create_tables.py if the tables already exist. This way, you can run create_tables.py whenever you want to reset your database and test your ETL pipeline.
- Launch a redshift cluster and create an IAM role that has read access to S3.
- Add redshift database and IAM role info to dwh.cfg.
- Test by running create_tables.py and checking the table schemas in your redshift database. You can use Query Editor in the AWS Redshift console for this.
- Build ETL Pipeline
- Implement the logic in etl.py to load data from S3 to staging tables on Redshift.
- Implement the logic in etl.py to load data from staging tables to analytics tables on Redshift.
- Test by running etl.py after running create_tables.py and running the analytic queries on your Redshift database to compare your results with the expected results.
- Delete your redshift cluster when finished.
- Document Process
Do the following steps in the README.md file.
- To run the scripts present in this project, the following informations need to be filled and saved as dwh.cfg in the project folder.
[CLUSTER]
HOST=''
DB_NAME=''
DB_USER=''
DB_PASSWORD=''
DB_PORT=5439
[IAM_ROLE]
ARN=
-
Run the create_tables script to set up the database staging and Analytical tables
$ python create_tables.py
-
Finally, run the etl script to extract data from the JSON files in S3, stage it in redshift, and finally load the data into the dimensional tables.
$ python create_tables.py