What is AWS EMR? Here’s Everything you Need to Know

Abhishek Kumar Last Updated : 04 Mar, 2024
9 min read

Introduction

How do you tackle the challenge of processing and analyzing vast amounts of data efficiently? This question has plagued many businesses and organizations as they navigate the complexities of big data. From log analysis to financial modeling, the need for scalable and flexible solutions has never been greater. Enter AWS EMR, or Amazon Elastic MapReduce.

In this article, we’ll look into the features and benefits of AWS EMR, exploring how it can revolutionize your data processing and analysis approach. From its integration with Apache Spark and Apache Hive to its seamless scalability on Amazon EC2 and S3, we’ll uncover the power of EMR and its potential to drive innovation in your organization. So, let’s embark on a journey to unlock the full potential of your data with AWS EMR.

What are Clusters and Nodes?

At the core of Amazon EMR lies the fundamental concept of a “Cluster” – a dynamic ensemble of Amazon Elastic Compute Cloud (Amazon EC2) instances, with each instance aptly referred to as a “node.” Within this cluster, each node undertakes a distinct role known as the “node type,” delineating its specific function in the distributed application landscape, encompassing prominent tools such as Apache Hadoop. Amazon EMR meticulously orchestrates the configuration of various software components on each node type, effectively assigning roles to nodes within the distributed application framework.

Types of Nodes in Amazon EMR

  • Primary Node: This authoritative force orchestrates the entire cluster, executing crucial software components to coordinate data distribution and task allocation among other nodes. The primary node diligently tracks task status and monitors overall cluster health. Every cluster inherently includes a primary node, and it’s even feasible to craft a single-node cluster exclusively featuring the primary node.
  • Core Node: Representing the backbone of the cluster, core nodes house specialized software components designed to execute tasks and store data in the Hadoop Distributed File System (HDFS). In multi-node clusters, at least one core node is integral to the architecture, ensuring seamless task execution and data storage.
  • Task Node: Task nodes play a focused role, exclusively running tasks without contributing to data storage in HDFS. Task nodes, while optional, enhance the versatility of the cluster by efficiently executing tasks without the overhead of data storage responsibilities.

Amazon EMR’s cluster structure optimizes data processing and storage with distinct node types, offering flexibility to tailor clusters to specific application demands.

Types of Nodes in Amazon EMR

Overview of Amazon EMR architecture

The foundational structure of the Amazon EMR service revolves around a multi-layered architecture, each layer contributing distinct capabilities and functionalities to the overall cluster operation.

Storage

The storage layer encompasses diverse file systems integral to your cluster. Notable options include:

Hadoop Distributed File System (HDFS)

A distributed, scalable file system designed for Hadoop, distributing data across cluster instances to ensure resilience against individual instance failures. HDFS serves purposes like caching intermediate results during MapReduce processing and handling workloads with significant random I/O.

EMR File System (EMRFS)

Extending Hadoop capabilities, EMRFS enables direct access to data stored in Amazon S3, seamlessly integrating it as a file system akin to HDFS. This flexibility allows users to opt for either HDFS or Amazon S3 as the file system, with Amazon S3 commonly used for storing input/output data and HDFS for intermediate results.

Local File System

Referring to locally connected disks, the local file system operates on preconfigured block storage attached to Amazon EC2 instances during Hadoop cluster creation. The data on these instance store volumes persists only for the duration of the respective Amazon EC2 instance’s lifecycle.

Cluster Resource Management

This layer governs the efficient allocation and scheduling of cluster resources for data processing tasks. Amazon EMR defaults to leveraging YARN (Yet Another Resource Negotiator), a component introduced in Apache Hadoop 2.0 for centralized resource management. While Spot Instances often run task nodes, Amazon EMR cleverly schedules YARN jobs to prevent failures caused by the termination of Spot Instance-based task nodes.

Data Processing Frameworks

The engine propelling data processing and analysis resides in this layer, with various frameworks catering to diverse processing needs, such as batch, interactive, in-memory, and streaming. Amazon EMR boasts support for key frameworks, including:

Hadoop MapReduce

An open-source programming model simplifies the development of parallel distributed applications by handling logic, while users provide Map and Reduce functions. It supports additional frameworks like Hive.

Apache Spark

A cluster framework and programming model for processing big data workloads, using directed acyclic graphs and in-memory caching for enhanced efficiency. Amazon EMR seamlessly integrates Spark, allowing direct access to Amazon S3 data via EMRFS.

Applications and Programs

Amazon EMR supports a plethora of applications like Hive, Pig, and Spark Streaming library, offering capabilities such as higher-level language processing, machine learning algorithms, stream processing, and data warehousing. Additionally, it accommodates open-source projects with their cluster management functionalities. Interacting with these applications involves utilizing various libraries and languages, including Java, Hive, Pig, Spark Streaming, Spark SQL, MLlib, and GraphX with Spark.

Also Read: Want to learn Cloud Computing? Begin your Journey with AWS!

Setting up your First EMR Cluster

AWS EMR Workflow

To set our first EMR Cluster we will follow these steps:

Creating a File System in S3

To initiate the establishment of the EMR file system, our first step involves the creation of an S3 bucket. Subsequently, within this bucket, we will generate a designated folder and implement server-side encryption. Further organization within this folder will include the generation of three subfolders: an Input Folder for receiving input data, an Output Folder for storing outputs from the EMR process, and a Logs Folder for maintaining relevant logs.

It is imperative to note that, during the creation of each of these folders, server-side encryption will be enabled to enhance security measures. The resulting folder structure will resemble the following:

└── emr-bucket123/

    └── monthly-bill/

        └── 2024-02/

            ├── Input

            ├── Output

            └── Logs
Creating a File System in S3

Create a VPC

Next on our agenda is the creation of a Virtual Private Cloud (VPC). In this setup, we’ll configure two public subnets with internet access, ensuring seamless connectivity. However, there won’t be any private subnets in this particular configuration.

For a comprehensive understanding and step-by-step guidance on crafting this VPC, feel free to explore the overview and instructions provided below:

Create a VPC
Create a VPC
Create a VPC

Configure EMR Cluster

After setting up, we’ll move on to creating an EMR Cluster. Once you click on the ‘Create Cluster’ option, default settings will be available:

Configure EMR Cluster

Then we will move on to Cluster Configuration but for this article, we won’t change anything we will keep the default configuration but you can Remove the Task node by selecting the remove instance group option for this use-case as you won’t need it that much for this.

Now in Networking, you have to choose the VPC that we created earlier:

Configure EMR Cluster

Now we will keep the things default and move on to Cluster Logs and browse to the S3 we have created earlier for logs.

Configure EMR Cluster

After configuring the logs you now have to set security configuration and EC2 key pair for your EMR you can use existing keys or create a new pair of keys.

Configure EMR Cluster
Configure EMR Cluster

IAM roles select the Create a service role option and provide the VPC you have created and put the default security group.

E2C Instance Profile
IAM Role

Now in EC2 instance profile for EMR select the Create an instance profile option and the give bucket access for all S3.

Now you are done with all the things for setting up your first EMR Cluster you launch your cluster by clicking on Create Cluster option.

Processing Data in an EMR Cluster

To effectively process data within an EMR cluster, we require a Spark script designed to retrieve and manipulate a specific dataset. For this article, we will be utilizing Food Establishment Data. Below is the Python script responsible for querying and handling the dataset(LINK):

from pyspark.sql import SparkSession
from pyspark.sql.functions import col
import argparse

def transform_data(data_source: str,output_uri: str)->None:
    with SparkSession.builder.appName("My EMR Application").getOrCreate() as spark:
        # Load CSV file
        df = spark.read.option("header","true").csv(data_source)

        #Rename Columns
        df = df.select(
            col("Name").alias("name"),
            col("Violation Type").alias("violation_type")
        )

        #create an in-memory dataframe
        df.createOrReplaceTempView("restaurant_violations")

        #Construct SQL Query
        GROUP_BY_QUERY='''
            SELECT name,count(*) AS total_violations
            FROM restaurant_violations
            WHERE violation_type="RED"
            GROUP BY name
            '''
        #Transform Data
        transformed_df = spark.sql(GROUP_BY_QUERY)

        #Log into EMR stdout
        print(f"Number of rows in SQL query:{transformed_df.count()}")

        #Write out results as parquet files
        transformed_df.write.mode("overwrite").parquet(output_uri)

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--data_source")
    parser.add_argument("--output_uri")
    args = parser.parse_args()
    transform_data(args.data_source, args.output_uri)

This script is designed to efficiently process Food Establishment Data within an EMR cluster, providing clear and organized steps for data transformation and output storage. 

Now upload the Python file in the S3 bucket and encrypt the file after uploading it.

 image.png

To run the EMR cluster you have to create steps. Navigate to your EMR Cluster, proceed to the “Step” option, and then click on “Add Step.”

Following that, provide the path to your Python script (accessible through the COPY S3 URI option) once you open the bucket in your web browser. Simply click on it and then paste the path into the application path and repeat the same process for the input dataset by entering the URI address of the bucket where the dataset is located (i.e., Input Folder in this case), and set the output source to the URI of the output bucket.

Arguments

 image.png

Now we can see the step is completed or not.

The data processing in EMR is now complete, and the resulting output can be observed in the designated output folder within the S3 bucket.

Maximizing Cost Efficiency and Performance with Amazon EMR

  • Leveraging Spot Instances: Amazon EMR offers the option to utilize Spot Instances, which are unused EC2 resources available at a reduced cost. By strategically integrating Spot Instances into clusters, organizations can realize substantial cost savings without sacrificing performance.
  • Introducing Instance Fleets: Amazon EMR introduces the notion of instance fleets, empowering users to allocate a combination of On-Demand and Spot Instances within a unified cluster. This adaptability allows organizations to find the optimal equilibrium between cost-effectiveness and availability.

Monitoring EMR Cluster

Monitoring an Amazon EMR (Elastic MapReduce) cluster is essential to ensure its health, performance, and efficient resource utilization. EMR provides several tools and mechanisms for monitoring clusters. Here are some key aspects you can consider:

  • Amazon CloudWatch Metrics
  • AWS EMR Console
  • Logging
  • Ganglia and Spark Web UI
  • Resource Utilization

Remember to adapt your monitoring strategy based on the specific requirements and characteristics of your workload and use case. Regularly review and update your monitoring setup to address changing needs and optimize cluster performance.

Also Read: AWS vs Azure: The Ultimate Cloud Face-Off

Conclusion

Amazon EMR offers a potent solution for big data processing, with a flexible and efficient platform for managing extensive datasets. Its cluster-based architecture, along with multi-layered components, ensures versatility and optimization for diverse application needs. Setting up an EMR cluster involves simple steps, and its integration with popular open-source frameworks enhances its appeal.

Demonstrating data processing within an EMR cluster using a Spark script illustrates the platform’s capabilities. Strategies like leveraging Spot Instances and Instance Fleets maximize cost efficiency, highlighting EMR’s commitment to providing cost-effective solutions.

Effective monitoring of EMR clusters is essential for maintaining performance and resource utilization. Tools like Amazon CloudWatch and logging features facilitate this monitoring process. Amazon EMR is a vital, user-friendly tool, providing seamless access to advanced data processing.

Frequently Asked Questions

Q1. What is Amazon EMR?

A. Amazon EMR, or Elastic MapReduce, is a cloud-based service by AWS designed for efficient big data processing using open-source tools like Apache Spark and Hive.

Q2. How does Amazon EMR optimize data processing?

A. EMR optimizes data processing through a cluster structure with primary, core, and task nodes, providing flexibility and efficiency for diverse application demands.

Q3. How do I set up an EMR Cluster on AWS?

A. Setting up an EMR Cluster involves creating an S3 bucket, configuring a VPC, and initializing the cluster through the AWS EMR Console.

Q4. What cost-efficiency strategies can be employed with EMR?

A. Cost efficiency strategies include leveraging Spot Instances and utilizing Instance Fleets for an optimal balance between cost-effectiveness and availability.

Q5. Why is monitoring important in EMR clusters?

A. Monitoring EMR clusters is essential for ensuring health, performance, and efficient resource utilization. Tools like Amazon CloudWatch and logging features assist in effective monitoring.

Hello, I'm Abhishek, a Data Engineer Trainee at Analytics Vidhya. I'm passionate about data engineering and video games I have experience in Apache Hadoop, AWS, and SQL,and I keep on exploring their intricacies and optimizing data workflows 

Responses From Readers

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details