DEV Community

AKSHARANETHRA NP
AKSHARANETHRA NP

Posted on

Exploring Serverless Data Analytics on AWS(Athena)

Akshara Meets Athena: Exploring Serverless Data Analytics on AWS

Tags: aws amazonathena cloudcomputing sql s3

In this blog, I explore Amazon Athena, a serverless AWS service that allows us to query data stored in Amazon S3 using SQL. I also demonstrate it using a Stranger Things dialogue dataset.


Introduction

Cloud computing provides many services for storing and analyzing data without requiring users to maintain physical infrastructure.

One such service is Amazon Athena, a serverless interactive query service from AWS. It allows users to analyze data stored in Amazon S3 using standard SQL, without setting up or managing database servers.

In this blog, I will explain what Amazon Athena is, why it was created, how it works, its key features, advantages and limitations. I will also demonstrate a practical use case using a Stranger Things dialogue dataset stored in Amazon S3.


What is Amazon Athena?

Amazon Athena is a serverless query service that allows users to run SQL queries directly on data stored in Amazon S3.

Unlike a traditional database, there is no need to create a database server before analyzing the data.

For example:

SELECT *
FROM stranger_things_dialogue
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Athena processes the query and returns the results without requiring us to manage the underlying servers.


Why Was Amazon Athena Created?

Organizations often store large amounts of data in Amazon S3. However, storing data in S3 alone does not provide a convenient way to perform SQL-based analysis.

A traditional approach could look like:

S3 → Database → SQL Query → Results
Enter fullscreen mode Exit fullscreen mode

This requires additional infrastructure.

Athena provides a simpler approach:

S3 → Amazon Athena → SQL Query → Results
Enter fullscreen mode Exit fullscreen mode

This makes it possible to analyze S3 data without provisioning or maintaining database infrastructure.


How Does Amazon Athena Work?

The working process is simple:

  1. Data is stored in an Amazon S3 bucket.
  2. Metadata about the data is defined using a table.
  3. Athena uses the AWS Glue Data Catalog to store metadata.
  4. The user writes an SQL query.
  5. Athena reads the required data from S3.
  6. The query results are displayed and can be stored in S3.

Architecture

                Student / User
                      |
                      | SQL Query
                      ↓
              +---------------+
              | Amazon Athena |
              +---------------+
                      |
                      ↓
             AWS Glue Data Catalog
                  (Metadata)
                      |
                      ↓
                +-----------+
                | Amazon S3 |
                |           |
                | CSV Data  |
                +-----------+
                      |
                      ↓
                Query Results
Enter fullscreen mode Exit fullscreen mode

Figure: Basic Amazon Athena architecture


Key Features

1. Serverless

Athena is serverless, so there is no need to provision or manage servers.

This allows developers and students to focus on analyzing data instead of managing infrastructure.

2. SQL-Based Queries

Athena supports SQL, which makes it easy to query datasets using familiar commands such as:

SELECT
WHERE
GROUP BY
ORDER BY
COUNT()
Enter fullscreen mode Exit fullscreen mode

3. Direct S3 Integration

Athena can query data directly from Amazon S3.

The original dataset can remain in S3 instead of being moved into a separate database.

4. Multiple Data Formats

Athena supports several data formats, including:

  • CSV
  • JSON
  • Parquet
  • ORC
  • Avro

5. Scalable Analytics

Athena can be used to analyze datasets ranging from small files to large data lakes without manually managing servers.


College / Student Use Case 🎓

Amazon Athena can be useful for college projects and departmental data analysis.

Example: Student Activity Analysis

Suppose a college stores student activity data in S3:

student_id
department
activity
timestamp
Enter fullscreen mode Exit fullscreen mode

Athena could be used to analyze the data using SQL.

For example:

SELECT department, COUNT(*) AS activity_count
FROM student_activity
GROUP BY department;
Enter fullscreen mode Exit fullscreen mode

This could help generate department-wise activity reports.

AIML Project Use Case

For an AIML student project, datasets can be stored in S3 and analyzed using Athena before being used for machine learning.

Dataset
   ↓
Amazon S3
   ↓
Amazon Athena
   ↓
Data Analysis
   ↓
Machine Learning
Enter fullscreen mode Exit fullscreen mode

My Practical Example

For my hands-on demonstration, I used a Stranger Things dialogue dataset.

The dataset was downloaded from Kaggle and extracted on an Amazon EC2 instance.

The extracted files included:

episodes.csv
stranger_things_all_dialogue.csv
Enter fullscreen mode Exit fullscreen mode

I then uploaded the dataset to my Amazon S3 bucket.

The S3 location was:

s3://akshara-s3-15-09-2026/stranger-things/
Enter fullscreen mode Exit fullscreen mode

The files were successfully uploaded using the AWS CLI.


Querying the Dataset with Athena

After creating the appropriate Athena table, I can query the dataset using SQL.

Retrieve Sample Records

SELECT *
FROM stranger_things_dialogue
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

This retrieves the first 10 records from the dataset.

Count Dialogue Records

SELECT COUNT(*) AS total_dialogues
FROM stranger_things_dialogue;
Enter fullscreen mode Exit fullscreen mode

This calculates the total number of dialogue records.

Filter by Season

SELECT *
FROM stranger_things_dialogue
WHERE season = 1;
Enter fullscreen mode Exit fullscreen mode

This retrieves dialogue records from Season 1.

Group by Character

SELECT character, COUNT(*) AS dialogue_count
FROM stranger_things_dialogue
GROUP BY character
ORDER BY dialogue_count DESC;
Enter fullscreen mode Exit fullscreen mode

This allows us to analyze the number of dialogue records associated with each character.


Advantages

No Server Management

There is no need to create or maintain database servers.

Easy to Use

Users familiar with SQL can start querying data quickly.

Cost Efficient for Suitable Workloads

Athena follows a serverless pricing model and charges primarily based on the amount of data scanned by queries.

Works Well with Data Lakes

Athena is well suited for analyzing data stored in Amazon S3.

Flexible

It supports different data formats and integrates with other AWS services.


Limitations / Things to Consider

Cost

Because pricing is related to the amount of data scanned, inefficient queries on large datasets can increase costs.

Using partitioning and efficient formats such as Parquet can help reduce unnecessary data scanning.

Complexity

Basic queries are simple, but advanced workloads may require knowledge of SQL, data formats and data organization.

Not a Transactional Database

Athena is primarily designed for analytics. It is not intended to replace a traditional database for applications requiring frequent transactional operations.

Security

Access to S3 and Athena resources should be controlled using appropriate AWS IAM permissions. Sensitive data should also be protected using suitable S3 security configurations.


Conclusion

Amazon Athena provides a simple way to perform SQL-based analytics on data stored in Amazon S3.

In my practical demonstration, I uploaded a Stranger Things dialogue dataset to S3 and explored how Athena can be used to query and analyze the data using SQL.

The complete workflow can be summarized as:

Dataset
   ↓
Amazon S3
   ↓
AWS Glue Data Catalog
   ↓
Amazon Athena
   ↓
SQL Query
   ↓
Query Results
Enter fullscreen mode Exit fullscreen mode

Amazon Athena demonstrates how cloud computing can make data analytics serverless, scalable and easier to manage.

For students, it is also a useful service for learning how S3-based data lakes and cloud analytics work.


References

Top comments (0)