Lesson 4 of 7 Analytics: Data Lakes, Athena, Glue, EMR, Redshift and QuickSight

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.

Match the pairs

Athena features

Exam skills 3.5.7 · 4.1.10

Match each requirement with the Athena feature that meets it.

Log in to try this activity Interactive activities are free with an account.

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.

NeedChoose
Occasional ad hoc queries on S3, no infrastructureAthena
Frequent, complex BI with many users and joinsRedshift
Large custom Spark or Hadoop processingEMR
Dashboards for business usersQuickSight
Sort into groups

Which analytics engine?

Exam skills 3.5.5 · 3.5.4

Choose the analytics service for each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing an analytics engine

Each analytics engine suits a different type of workload. The following table identifies the appropriate engine for several requirements.

RequirementChoice
Occasional SQL queries on log files in S3, no infrastructureAthena
Dashboards for 200 analysts with sub-second queries over years of salesRedshift
Existing Spark and Hadoop jobs processing petabytesAmazon EMR
Interactive dashboards for business usersAmazon QuickSight
Query S3 data from Redshift without loading itRedshift 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.

Check yourself

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.