- Move timesfm-forecast into apps/ directory - Flatten Udacity portfolio projects from deep URL-encoded paths into data-engineering/01-XX numbered directories - Remove old My-Data-Engineering-Portifolio/ parent directory - Rewrite root README.md: professional overview with badges, project table, and repo structure diagram - Create data-engineering/README.md with per-project descriptions - Add README.md for 02-cassandra-modeling (was missing) - Add README.md for 05-airflow-pipelines (was missing) - Normalize capstone readme.md -> README.md - Update .gitignore: add *.cfg, *.env, *.zip, *.sas7bdat, Jupyter checkpoints, IDE dirs; remove uv.lock exclusion - Add dwh.cfg.example and dl.cfg.example credential templates - Untrack real credential files (dwh.cfg, dl.cfg) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4.1 KiB
Project 3: Song Play Analysis with S3 and Redshift
Introduction
In this project, we will help one music streaming startup - Sparkify, to move their user and song database processes to the cloud. To reach that, we build an ETL pipeline to extracts their data from AWS S3 (data storage), stages tables on AWS Redshift (data warehouse with columnar storage), and execute SQL statements to create the analytics tables from these staging tables.
Datasets
Datasets used in this project are provided in two public S3 buckets.
- Song Dataset - 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 file paths to two files in this dataset.
song_data/A/B/C/TRABCEI128F424C983.json
song_data/A/A/B/TRAABJL12903CDCF1A.json
And below is an example of what a single song file, TRAABJL12903CDCF1A.json, 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}
- Log Dataset - 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 you'll be working with are partitioned by year and month. For example, here are file paths to two files in this dataset.
log_data/2018/11/2018-11-12-events.json
log_data/2018/11/2018-11-13-events.json
And below is an example of what the data in a log file, 2018-11-12-events.json, looks like.
The Redshift service is where data will be ingested and transformed, using COPY command we will access to the JSON files inside the buckets and copy their content to our staging tables.
Database Schema
We have two staging tables which copy the JSON file inside the S3 buckets.
Staging Tables
- staging_songs - info about songs and artists
- staging_events - actions done by users (which song are listening, etc.. )
A star schema was designed to optimize queries on song play analysis. This includes the following tables.
Fact Table
- songplays - records in event data associated with song plays i.e. records with page
NextSong
Dimension Tables
- users - users in the app
- songs - songs in music database
- artists - artists in music database
- time - timestamps of records in songplays broken down into specific units
The database schema is shown as follows
Data Warehouse Configurations and Setup steps:
- Create a new
IAM userin your AWS account - Give it AdministratorAccess and Attach policies
- Use access key and secret key to create clients for
EC2,S3,IAM, andRedshift. - Create an
IAM Rolethat makesRedshiftable to accessS3 bucket(ReadOnly) - Create a
RedShift Clusterand get theDWH_ENDPOIN(Host address)andDWH_ROLE_ARNand fill the config file.
ETL Pipeline
- Created tables to store the data from
S3 buckets. - Loading the data from
S3 bucketsto staging tables in theRedshift Cluster. - Inserted data into fact and dimension tables from the staging tables.
Project Structure
create_tables.py- This script will drop old tables (if exist) ad re-create new tables.etl.py- This script executes the queries that extractJSONdata from theS3 bucketand ingest them toRedshift.sql_queries.py- This file contains variables with SQL statement in String formats, partitioned byCREATE,DROP,COPYandINSERTstatement.dhw.cfg- Configuration file used that contains info aboutRedshift,IAMandS3
How to Run
-
Create tables by running
create_tables.py. -
Execute ETL process by running
etl.py.