
Query Data Without a Database: Serverless SQL with Amazon S3 and Athena
This article walks through how the pair works, why it's popular for analytics, and how to try it yourself in under an hour.
Most people learning data analytics assume that to run SQL, you first need a database: install it, load the data, manage the server. On AWS, there's a quicker route. With Amazon S3 and Amazon Athena, you can leave your data in plain files and query it with standard SQL, with no servers to set up and nothing to load.
The Big Idea: Separate Storage from Compute
Traditional databases bundle storage and processing together. Athena splits them apart:
- Amazon S3 is the storage layer. It holds your data as files (CSV, JSON, Parquet, and more) in buckets, cheaply and at almost any scale.
- Amazon Athena is the query layer. It's an interactive, serverless query service that reads those files directly and returns results using SQL.
Because Athena is serverless, there's no cluster to size or maintain. You write a query, Athena runs it, and you pay only for the data it scans.
How Athena Works
Athena doesn't store data itself. Instead, it relies on table definitions that tell it where your files live and what the columns look like. These definitions are kept in the AWS Glue Data Catalog, which Athena uses as its metadata store.
The flow looks like this:
- Upload files to an S3 bucket.
- Define a table over that location (manually with a
CREATE EXTERNAL TABLEstatement, or automatically with a Glue crawler).
- Run SQL queries in the Athena console or from tools that connect to it.
- Results land in another S3 location you specify, and you can download or visualize them from there.
If you know SELECT, WHERE, GROUP BY, JOIN, and window functions, you already know most of what you need. Athena uses a Presto/Trino-based SQL dialect that will feel familiar.
A Minimal Example
Suppose you have a CSV of sales orders in
s3://my-bucket/sales/ . You could create a table like this:CREATE EXTERNAL TABLE sales ( order_id string, order_date date, region string, product string, quantity int, revenue double)ROW FORMAT DELIMITEDFIELDS TERMINATED BY ','LOCATION 's3://my-bucket/sales/'TBLPROPERTIES ('skip.header.line.count'='1');Then analyze it like any other table:
SELECT region, SUM(revenue) AS total_revenue, COUNT(DISTINCT order_id) AS ordersFROM salesGROUP BY regionORDER BY total_revenue DESC;No loading step, no server. The data stays in S3 the whole time.
Cost and Performance: Two Habits That Matter
Athena charges based on the amount of data scanned by each query. That makes a few habits worth building early:
1. Use columnar formats like Parquet. CSV forces Athena to read every column of every row. Parquet stores data by column and compresses well, so queries that touch only a few columns scan far less data. Converting CSV to Parquet (a common job for AWS Glue) can cut both cost and query time significantly.
2. Partition your data. If your files are organized into folders like
year=2026/month=11/ , Athena can skip entire folders that don't match your WHERE clause. Partitioning by a column you often filter on, such as date, is one of the most effective optimizations available.A few smaller habits help too: select only the columns you need instead of using
SELECT * , and use LIMIT while exploring.Where Athena Fits in the Bigger Picture
Athena is not a replacement for a data warehouse like Redshift. A rough guide:
Use case | Good fit |
|---|---|
Ad hoc exploration of files in S3 | Athena |
Querying logs, exports, and raw data lakes | Athena |
Occasional or unpredictable query workloads | Athena |
Heavy, repeated, high-concurrency BI workloads | Redshift |
Complex, tuned, multi-user warehouse | Redshift |
Many teams use both: Athena to explore and validate raw data in the lake, and Redshift for curated, heavily used reporting tables. Results from either can feed dashboards in Amazon QuickSight.
Try It Yourself
A simple hands-on path for a beginner:
- Create an S3 bucket and upload a small CSV dataset (any public sample data works).
- Open Athena, set a query results location in S3, and create a database.
- Create an external table over your file and run a few aggregation queries.
- Experiment: convert the data to Parquet, partition it, and compare how much data each query scans.
That last step is where the lesson really lands. Seeing the "data scanned" number drop after a format change teaches you more about cloud analytics cost than any documentation will.
Final Thoughts
S3 plus Athena turns SQL skills into something you can apply directly to raw files, with almost no setup. It's a low-risk way to practice cloud analytics, and the habits it teaches (columnar formats, partitioning, and cost-aware querying) carry over to every other AWS analytics service.
Tip: AWS pricing and free-tier terms change over time, so check the current Athena and S3 pricing pages before running large queries.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article