Skip to content

Building Data Lake and ETL pipelines using Amazon EMR, S3, and Apache Spark

Notifications You must be signed in to change notification settings

Faisal-AlDhuwayhi/Data-Lake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Data Lake

A music streaming startup, Sparkify, has grown their user base and song database even more and want to move their data warehouse to a data lake. 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. Therefore, The task is to:

  • build an ETL pipeline that extracts their data from S3.
  • processes them using Spark.
  • and loads the data back into S3 as a set of dimensional tables.

That is to be able to have better analytical processes by utilizing data hosted on a Data Lake using an AWS service called Amazon EMR (previously called Amazon Elastic MapReduce), and to continue finding insights into what songs their users are listening to.

Dataset

You'll be working with two datasets that reside in S3, which are:

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.

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 activity logs from a music streaming app based on specified configurations. The log files in the dataset you'll be working with are partitioned by year and month.

Methodology

In this project, the work process is focused on building an ETL pipeline that:

  • extract the data from S3 data lake, which consists of the two mentioned datasets, Song and Log datasets.

  • process the data using Spark to be converted and transformed to a set of dimensional tables.

  • load the data back into S3 data lake as a set of dimensional tables to prepare the data for further analytics and usage of business intelligence tools.

We transformed the song and log datasets that resides in our data lake using Spark to several dimensional tables with Star schema optimized for queries on song play analysis. This includes the following tables:

Fact Table

  1. songplays - records in log 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

Dimension Tables

  1. users - users in the app

    • user_id, first_name, last_name, gender, level
  2. songs - songs in music database

    • song_id, title, artist_id, year, duration
  3. artists - artists in music database

    • artist_id, name, location, latitude, longitude
  4. time - timestamps of records in songplays broken down into specific units

    • start_time, hour, day, week, month, year, weekday

The above Star schema satisfies the needs of simpler queries and faster aggregation, Which make it a suitable choice to the project problem.

Usage

To work on this project, you need first to install Python in your machine. Then, install the following dependencies:

  • Pyspark

However, due to the big size of the data it is recommended to use the resources of AWS EMR to complete the project.

Steps

To complete the project, you need to follow these steps:

  1. Create AWS EMR cluster.

  2. Create a notebook inside the Amazon EMR section and assign it to the created EMR cluster (this notebook would be your draft work).

  3. Add AWS credentials info in dl.cfg.

  4. Put your work from the notebook inside etl.py, then run it from terminal to implement your ETL pipeline:

    python etl.py