Querying S3 Data with Amazon Athena
This lesson explains how Amazon Athena runs serverless SQL queries directly on data in S3, with no infrastructure to manage and no data to load.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how Athena works with the Glue Data Catalog.
- Identify typical uses such as log analysis.
- Choose an analytics engine.
How Athena works
Amazon Athena runs SQL queries directly against data in Amazon S3, using table definitions from the AWS Glue Data Catalog, with no servers to manage. It is priced per terabyte of data scanned, so storing data as Parquet or ORC, compressing it and partitioning it reduce both cost and query time.
CTAS (CREATE TABLE AS SELECT) queries write their results as new tables, which is a simple way to convert CSV into partitioned Parquet. Federated queries reach other sources, such as DynamoDB or RDS, through Lambda-based connectors. Workgroups separate teams and can cap the amount of data each query may scan, which prevents runaway costs.
Athena features
Typical uses
Athena suits occasional, ad hoc SQL over data already in S3. A common use is analysing logs that AWS services deliver to S3, such as CloudTrail logs, Application Load Balancer access logs and VPC Flow Logs, to investigate incidents or traffic patterns. Others are exploring a data lake before building pipelines, and querying the AWS Cost and Usage Report to analyse spending in detail.
Choosing an analytics engine
The analytics engine is chosen by how often, how complex and how large the analysis is. Athena runs SQL queries directly on data in S3 with no infrastructure, charging per data scanned, which suits occasional, ad hoc queries. Redshift is a data warehouse for frequent, complex business intelligence queries with many concurrent users and large joins, where consistent performance matters.
EMR runs Spark, Hadoop and other open-source frameworks for large custom processing jobs, such as machine learning feature engineering. QuickSight provides dashboards and reports for business users on top of these sources. The following table summarises the choice.
| Need | Choose |
|---|---|
| Occasional ad hoc queries on S3, no infrastructure | Athena |
| Frequent, complex BI with many users and joins | Redshift |
| Large custom Spark or Hadoop processing | EMR |
| Dashboards for business users | QuickSight |
Which analytics engine?
Choosing an analytics engine
Each analytics engine suits a different type of workload. The following table identifies the appropriate engine for several requirements.
| Requirement | Choice |
|---|---|
| Occasional SQL queries on log files in S3, no infrastructure | Athena |
| Dashboards for 200 analysts with sub-second queries over years of sales | Redshift |
| Existing Spark and Hadoop jobs processing petabytes | Amazon EMR |
| Interactive dashboards for business users | Amazon QuickSight |
| Query S3 data from Redshift without loading it | Redshift Spectrum |
Athena suits ad hoc, infrequent queries billed per data scanned; Redshift suits constant, heavy analytical use by many users; EMR suits custom big data frameworks.
How is Athena charged?
Show answer
By the amount of data each query scans, so compression, columnar formats and partitioning reduce the cost.
Exam Tips
Remember for the exam
- For ad hoc SQL on S3 with no infrastructure, use Athena.
- To cut Athena cost, use Parquet, compression and partitioning.
- To query CloudTrail or ALB logs in S3, use Athena.
- To cap the data each team's queries can scan, use Athena workgroups.