Reading30 min read·Module 3

Amazon Athena & Redshift

Key concepts

  • Athena serverless queries

  • Redshift data warehouse

  • Redshift Spectrum

  • Query optimization

  • Data formats (Parquet, ORC)

Overview

Amazon Athena and Amazon Redshift are AWS analytics services for querying large datasets with SQL (Structured Query Language, the standard language for relational queries). Athena is a serverless query engine that reads data directly from Amazon S3 (Simple Storage Service, the object store) with no clusters to manage and per-query pricing based on data scanned. Amazon Redshift is a managed, petabyte-scale data warehouse that loads data into clustered storage for fast, repeated analytical queries, and Redshift Spectrum lets a Redshift cluster query data still sitting in S3 without loading it first.

This topic is high-yield on the SAA-C03 exam through "which analytics service" scenarios. You should know when serverless ad hoc querying (Athena) beats a provisioned warehouse (Redshift), how Redshift Spectrum bridges the warehouse and the data lake, and how columnar formats such as Parquet and ORC plus partitioning reduce both query time and cost.

Serverless Queries vs Managed Warehouse

Choose Athena for serverless, ad hoc, infrequent SQL directly over S3 with no infrastructure to run. Choose Redshift when you need a persistent warehouse for frequent, complex, high-performance analytics over loaded data, and use Redshift Spectrum to extend that warehouse to data still in S3.

Exam Tip

Athena is serverless and priced per terabyte scanned, so columnar formats (Parquet, ORC), compression, and partitioning cut both cost and runtime. Redshift is a provisioned warehouse priced per node hour. Redshift Spectrum queries S3 directly from a Redshift cluster and is priced like Athena, per terabyte scanned.


Key Concepts

Athena Serverless Queries

SQL Directly Over S3

Amazon Athena is an interactive query service that runs standard SQL (using the Trino and Presto engines) against data stored in S3. It is serverless, so there are no clusters to provision: you define a table schema in the AWS Glue Data Catalog (a managed metadata store that maps files in S3 to table and column definitions), point it at an S3 location, and query. Pricing is based on the amount of data scanned per query (about $5 per terabyte scanned), so reducing scanned data directly reduces cost. Athena suits ad hoc analysis, log querying, and infrequent reporting where standing up a warehouse is not justified.

SQLCreate a Table and Query It in Athena
-- Define a table over Parquet files in S3 (schema-on-read)
CREATE EXTERNAL TABLE access_logs (
  request_time string,
  status int,
  bytes_sent bigint
)
STORED AS PARQUET
LOCATION 's3://my-logs-bucket/access/';

-- Athena scans only the columns and partitions the query touches
SELECT status, COUNT(*) AS hits
FROM access_logs
WHERE status >= 500
GROUP BY status;

Redshift Data Warehouse

A Managed, Columnar Warehouse

Amazon Redshift is a fully managed data warehouse built for online analytical processing (OLAP, meaning aggregations and scans across large tables rather than many small transactional reads and writes). Data is loaded into a cluster of nodes (a leader node that plans queries plus compute nodes that store and process data) using columnar storage, compression, and massively parallel processing (MPP, where work is split across all compute nodes at once). You can run a provisioned cluster (priced per node hour) or Redshift Serverless (priced per usage). Redshift fits frequent, complex joins and aggregations over large, structured datasets, such as business-intelligence dashboards.

Athena vs Redshift

DimensionAmazon AthenaAmazon Redshift
ModelServerless query engineProvisioned or serverless warehouse
Where data livesIn S3, queried in placeLoaded into the cluster
PricingPer terabyte scannedPer node hour (or per usage)
Best forAd hoc, infrequent queriesFrequent, complex analytics
SetupNone, just define schemaProvision and load data

Redshift Spectrum

Query S3 From the Warehouse

Redshift Spectrum lets a Redshift cluster run SQL against data stored in S3 without loading it into the cluster first. You keep hot, frequently joined data in Redshift tables and leave large, cold, or rarely queried data in S3, then join across both in one query. Spectrum uses a separate fleet of compute managed by AWS and is priced per terabyte scanned, like Athena. This is the standard pattern for extending a warehouse to a data lake (a large repository of raw data in S3) without growing the cluster.

Redshift Tables vs Redshift Spectrum

DimensionRedshift Local TablesRedshift Spectrum
Data locationInside the clusterIn S3
Loading requiredYes (COPY command)No
PricingPer node hourPer terabyte scanned
Best forHot, frequently queried dataCold or rarely queried data

Query Optimization

Scan Less, Query Faster

For Athena and Spectrum, the dominant lever is reducing data scanned: store data column by column, compress it, and partition it (organize files into folders by a column such as date so the engine skips irrelevant partitions). Selecting only needed columns also lowers scan volume. For Redshift, performance comes from the distribution style (DISTKEY, which controls how rows spread across nodes to keep joins on the same node) and the sort key (SORTKEY, which orders rows on disk so range scans skip blocks). Choosing these well minimizes data shuffled between nodes and blocks read from disk.

Optimization Levers by Service

GoalAthena / SpectrumRedshift
Reduce data scannedColumnar format and compressionColumnar storage (built in)
Skip irrelevant dataPartition by date or keySORTKEY for range scans
Speed up joinsPre-aggregate or partitionDISTKEY co-locates join rows
Lower costScan fewer terabytesRight-size and pause clusters

Data Formats (Parquet, ORC)

Columnar Formats Cut Cost and Time

Parquet and ORC (Optimized Row Columnar) are open columnar file formats: they store values column by column rather than row by row. Because Athena, Spectrum, and Redshift read only the columns a query needs, a columnar format scans far less data than row formats like CSV or JSON, which lowers both runtime and the per-terabyte-scanned bill. Both formats also support compression (such as Snappy) and store statistics that let engines skip blocks. Converting raw CSV or JSON to Parquet or ORC is one of the highest-impact optimizations for S3-based analytics.

Row vs Columnar Formats

AspectCSV / JSON (row)Parquet / ORC (columnar)
Storage layoutRow by rowColumn by column
Data scanned per queryEntire rowsOnly needed columns
CompressionLimitedStrong (Snappy, Zstandard)
Athena cost impactHigherMuch lower
Best forRaw ingest, interchangeAnalytics queries

Best Practices

TEXTDesign Guidance
1. Match the service to the query pattern
   ├── Athena: ad hoc, infrequent SQL over S3
   └── Redshift: frequent, complex, high-performance analytics

2. Store analytics data in Parquet or ORC
   ├── Scans only needed columns, cutting cost and time
   └── Convert raw CSV/JSON during ingest (Glue or CTAS)

3. Partition S3 data by a common filter column
   └── Partition by date so Athena skips irrelevant folders

4. Tune Redshift with DISTKEY and SORTKEY
   ├── DISTKEY co-locates rows that join together
   └── SORTKEY orders rows so range scans skip blocks

5. Use Redshift Spectrum for cold data
   └── Keep hot data in the cluster, query S3 data in place

6. Compress data and select only needed columns
   └── Lowers terabytes scanned on Athena and Spectrum

Common Pitfalls

Pitfall 1: Provisioning Redshift for Infrequent Queries

Mistake: Standing up a Redshift cluster for a few ad hoc reports per week.

Why it fails: A provisioned cluster bills per node hour around the clock, so infrequent use wastes money compared to a serverless option.

Correct Approach: Use Athena for ad hoc, infrequent SQL directly over S3, and reserve Redshift for frequent, complex analytics.

Pitfall 2: Querying Raw CSV or JSON in Athena

Mistake: Leaving large datasets as uncompressed CSV or JSON and querying them with Athena.

Why it fails: Athena charges per terabyte scanned, and row formats force scanning entire rows, which raises both cost and query time.

Correct Approach: Convert data to Parquet or ORC with compression and partition it so each query scans far less data.

Pitfall 3: Loading Cold Data Into the Cluster

Mistake: Copying rarely queried historical data into Redshift to join it with current data.

Why it fails: Cold data consumes cluster storage you pay for continuously and forces you to scale nodes you rarely use.

Correct Approach: Keep cold data in S3 and join it on demand with Redshift Spectrum, which is priced per terabyte scanned.

Pitfall 4: Ignoring Distribution and Sort Keys

Mistake: Loading Redshift tables without choosing a DISTKEY or SORTKEY.

Why it fails: Poor distribution shuffles large amounts of data between nodes during joins, and missing sort keys force full scans, both of which slow queries.

Correct Approach: Pick a DISTKEY on common join columns and a SORTKEY on common filter or range columns to minimize data movement and disk reads.


Test Your Knowledge

Q

A data team needs to run occasional ad hoc SQL queries against several terabytes of application logs already stored in S3, with no infrastructure to manage and the lowest steady cost. Which service fits best?

AProvision an Amazon Redshift cluster and load the logs
BUse Amazon Athena to query the logs directly in S3
CLaunch an EMR cluster with Spark
DImport the logs into an RDS database
Q

An analytics platform runs Redshift for frequent dashboards over recent sales, but five years of historical orders sit in S3 and are queried only a few times a month. The team wants to join recent and historical data without growing the cluster. What should the architect recommend?

ALoad all historical data into Redshift with the COPY command
BUse Redshift Spectrum to query the historical data in S3
CReplace Redshift with Athena entirely
DCopy the historical data into a second Redshift cluster
Q

Athena queries over a large dataset of CSV files in S3 are slow and expensive because each query scans the full dataset. Which change reduces both query time and cost the most?

AIncrease the Athena query timeout
BConvert the data to Parquet with compression and partition by date
CMove the data to a larger S3 bucket
DRun the queries during off-peak hours


Quick Reference

Decision Summary

Quick Decisions

If you need...Choose
Serverless ad hoc SQL over S3Athena
Frequent complex analytics on loaded dataRedshift
Query S3 from a Redshift clusterRedshift Spectrum
Lower scan cost and faster queriesParquet or ORC plus partitioning
The data lake storage layerAmazon S3

Service Characteristics

Pricing and Limits

ItemDetail
Athena pricingAbout $5 per terabyte scanned
Athena infrastructureServerless, no clusters
Redshift pricingPer node hour, or per usage on Serverless
Redshift Spectrum pricingPer terabyte scanned in S3
Recommended analytics formatParquet or ORC, compressed

Common CLI Commands

SHAthena and Redshift CLI
# Start an Athena query and write results to S3
aws athena start-query-execution \
  --query-string "SELECT status, COUNT(*) FROM access_logs GROUP BY status" \
  --result-configuration "OutputLocation=s3://my-athena-results/"

# Check the status of an Athena query
aws athena get-query-execution --query-execution-id 0a1b2c3d-4e5f-6789-abcd-ef0123456789

# Create a Redshift Serverless workgroup
aws redshift-serverless create-workgroup \
  --workgroup-name analytics-wg --namespace-name analytics-ns

# Create a provisioned Redshift cluster
aws redshift create-cluster \
  --cluster-identifier prod-dw --node-type ra3.xlplus \
  --number-of-nodes 2 --master-username admin --master-user-password ChangeMe123

Further Reading

Related services

AthenaRedshiftS3