Study guide
Technical reference and lesson notes
Amazon Athena and AWS Glue: Querying, Cataloging, and Preparing Data for CloudOps
Purpose of This Lesson
This lesson explains how Amazon Athena and AWS Glue work together to make data in AWS queryable and usable for analytics. The main assessment focus is recognizing when to use Athena for SQL queries, when Glue is needed for cataloging or ETL, and how to improve Athena query performance.
Key Concepts
Amazon Athena
Amazon Athena is a serverless query service that runs SQL queries against data, principally data stored in Amazon S3. Athena can query several common data formats:
- CSV
- TSV
- JSON
- Apache Parquet
- Apache ORC
Athena does not require the data to be loaded into a separate database before it can be queried. Instead, it needs table definitions that describe the structure and location of the data.
AWS Glue Data Catalog
The AWS Glue Data Catalog is a managed metadata repository. It stores information such as database and table definitions, schemas, and data locations. Athena can use these cataloged tables when constructing and executing SQL queries.
AWS Glue ETL
AWS Glue is a fully managed extract, transform, and load (ETL) service. It prepares and transforms data for analytics and runs ETL jobs on a managed, scale-out Apache Spark environment.
Glue can work with several AWS data storage categories, including:
- Data lakes such as Amazon S3
- Data warehouses such as Amazon Redshift
- Data stores such as Amazon RDS and Amazon EC2-based data sources
Glue Crawlers
A Glue crawler discovers data and populates the Glue Data Catalog with table definitions. A crawler can inspect multiple data stores during one run. When it finishes, it creates new catalog tables or updates existing ones.
Glue ETL jobs can then use catalog tables as their sources and targets. Athena can also use those same catalog tables to query the underlying data.
Athena and Glue Workflow
A common workflow is:
- Store raw or processed data in Amazon S3.
- Use an AWS Glue crawler to discover the data structure.
- Allow the crawler to create or update tables in the Glue Data Catalog.
- Use Athena to query the cataloged S3 data with SQL.
- If required, use AWS Glue ETL jobs to extract, transform, and load the data into a more useful format or destination.
- Query the transformed data with Athena.
Glue is not mandatory for every Athena use case, but it is a convenient managed way to maintain the metadata Athena needs. Athena can also use other data sources through supported integrations.
Connecting Athena to Other Data Sources
Although Athena is principally used with data in S3, it can be connected to other data sources. Some integrations require an AWS Lambda function. In that design:
- Athena invokes or uses the integration involving Lambda.
- Lambda connects to the external data source.
- The source data is mapped into Athena tables.
- SQL queries are run against those tables.
For example, Athena can be used to query information from CloudWatch Logs when a Lambda-based connection is used. The important decision point is that Athena does not automatically query every external service directly; the required integration mechanism must be present.
Athena Query Performance Optimization
The lecture identifies several optimization recommendations that may appear in CloudOps assessment scenarios:
- Partition data: Organize data into partitions so Athena can scan only the relevant portions.
- Bucket data within a single partition: Use bucketing where appropriate to organize records inside a partition.
- Compress data: Compression reduces the amount of data that must be read. Apache Parquet and Apache ORC are recommended formats.
- Optimize file sizes: Avoid poorly sized files that create inefficient query processing.
- Optimize columnar data storage generation: Use column-oriented formats and generate them efficiently.
- Optimize
ORDER BYandGROUP BY: These operations can require substantial processing, so query design matters. - Use approximate functions when appropriate: Approximate calculations can reduce processing requirements when exact results are not necessary.
- Select only required columns: Avoid retrieving columns that the query does not need.
The strongest general pattern is to reduce the amount of data Athena must scan and process.
Exam- or Assessment-Relevant Takeaways
- Choose Amazon Athena when the requirement is to run SQL queries against data, especially data stored in Amazon S3.
- Choose AWS Glue Data Catalog when Athena needs managed schemas, table definitions, or metadata about data sources.
- Choose a Glue crawler when table metadata must be discovered automatically or existing catalog tables must be updated.
- Choose AWS Glue ETL when data must be extracted, transformed, and loaded for analytics.
- Recognize Parquet and ORC as columnar formats associated with Athena performance optimization.
- Improving Athena performance generally involves reducing data scanned through partitioning, compression, file-size optimization, and selecting only needed columns.
- If Athena must access a source such as CloudWatch Logs through an external integration, look for the requirement to use Lambda to connect and map the source into Athena tables.
Tool / Feature Decision Guide
| Requirement | Best fit | Reason |
|---|---|---|
| Run SQL against files in Amazon S3 | Amazon Athena | Athena queries supported data in place using SQL. |
| Store schemas, table definitions, and data-source metadata | AWS Glue Data Catalog | The catalog provides managed metadata for Athena and Glue. |
| Automatically discover or update table definitions | AWS Glue crawler | Crawlers inspect data stores and create or update catalog tables. |
| Extract, transform, and load data | AWS Glue ETL | Glue provides managed ETL jobs on a scale-out Apache Spark environment. |
| Query an external source such as CloudWatch Logs through an integration | Athena with Lambda-based integration | Lambda connects to the source and exposes the data through Athena tables. |
| Reduce Athena scan and processing cost | Partitioning, compression, columnar formats, and selective queries | These approaches reduce the amount of data Athena must process. |
Common Traps / Misconceptions
- Athena is not the same as Glue. Athena is the SQL query service; Glue provides cataloging and managed ETL capabilities.
- Glue does not mean that data must be moved into Glue. The Glue Data Catalog stores metadata, while the underlying data can remain in sources such as S3.
- A crawler is not an ETL job. A crawler discovers schemas and updates the catalog. An ETL job transforms and moves or prepares data.
- Athena is not limited to CSV. CSV, TSV, JSON, Parquet, and ORC are all identified as supported formats in the lesson.
- External data sources may need an integration component. Querying a source such as CloudWatch Logs can require Lambda to connect the source to Athena.
- Using SQL alone does not guarantee good performance. Poor partitioning, unnecessary columns, inefficient file sizes, and uncompressed data can increase the amount of data processed.
- A Glue crawler can handle more than one data store in a run. Do not assume that each crawler execution is limited to one source.
Real-World Engineer / Analyst Notes
- Treat the Glue Data Catalog as the shared metadata layer between discovery, ETL, and querying.
- Separate the questions “Where is the data?” and “How is the data described?” The data may be in S3 while its schema and table definition are stored in Glue.
- For recurring analytics, standardize transformed data into efficient formats such as Parquet or ORC where appropriate.
- When troubleshooting an Athena query, check whether the query is scanning unnecessary partitions or columns and whether the source files are efficiently organized.
- A crawler can simplify initial discovery, but catalog accuracy still matters. Schema changes and source changes can require catalog updates.
- When a requested source is not directly queryable through Athena, identify the integration path rather than assuming Athena can access it natively.
Quick Reference Summary
- Athena: Serverless SQL queries, principally against S3 data.
- Supported formats: CSV, TSV, JSON, Apache Parquet, and Apache ORC.
- Glue Data Catalog: Managed metadata store containing schemas, databases, tables, and source information.
- Glue crawler: Discovers data and creates or updates catalog tables; can crawl multiple data stores in one run.
- Glue ETL: Managed extract, transform, and load service using a scale-out Apache Spark environment.
- Shared workflow: Glue discovers and catalogs data; Glue ETL can transform it; Athena queries it.
- External integrations: Some sources, such as CloudWatch Logs, require Lambda to connect and map data into Athena tables.
- Performance: Partition data, bucket within partitions, compress it, use Parquet or ORC, optimize file sizes and query operations, use approximate functions where suitable, and select only needed columns.
Flashcards
Q: A team needs to run SQL queries directly against files stored in Amazon S3 without loading them into a traditional database. Which service should it choose?
A: Amazon Athena. It runs SQL queries against supported data in place, principally in Amazon S3.
Q: What role does the AWS Glue Data Catalog play in an Athena solution?
A: It stores managed metadata such as database, table, schema, and data-location information that Athena can use to build queries.
Q: When should a team use a Glue crawler rather than an ETL job?
A: Use a crawler to discover data and create or update catalog tables. Use an ETL job when the data itself must be extracted, transformed, or loaded.
Q: A data lake contains CSV, JSON, and Parquet files. Can Athena query all of these formats according to the lesson?
A: Yes. Athena can query CSV, TSV, JSON, Apache Parquet, and Apache ORC data.
Q: What is the main performance benefit of partitioning data for Athena?
A: Partitioning can allow Athena to scan only relevant portions of the data instead of scanning the full dataset.
Q: Why are Apache Parquet and Apache ORC useful choices for Athena data?
A: They are recommended compressed, columnar formats that can reduce the amount of data Athena reads and processes.
Q: An analyst needs to query CloudWatch Logs with Athena, but the source is not directly available as an S3 table. What additional component may be required?
A: A Lambda-based integration may be required to connect to the data source and map its data into Athena tables.
Q: How do Athena and AWS Glue differ in their primary purposes?
A: Athena primarily queries data with SQL, while Glue provides data cataloging and managed ETL capabilities.
Q: What happens when a Glue crawler completes successfully?
A: It creates new tables or updates existing tables in the Glue Data Catalog based on the data it discovered.
Q: Can a Glue crawler inspect multiple data stores during one run?
A: Yes. The lesson specifically identifies the ability to crawl multiple data stores in a single run.
Q: A query selects ten columns, but only two are needed for the report. What Athena optimization should be applied?
A: Select only the required columns. Avoiding unnecessary columns reduces the data Athena must process.
Q: What is the purpose of AWS Glue ETL in an Athena-based analytics workflow?
A: Glue ETL prepares and transforms data for analytics, after which Athena can query the resulting data.
Practice Questions
Question 1
A CloudOps team wants to query data in Amazon S3 using SQL. The data is already in a supported format, and the team wants a managed location for its schemas and table definitions. Which combination best fits the requirement?
A. Amazon RDS and AWS Lambda
B. Amazon Athena and the AWS Glue Data Catalog
C. AWS Glue crawler and Amazon Redshift only
D. Amazon EC2 and Amazon CloudWatch Logs
Correct answer: B
Explanation: Athena provides the SQL query capability, while the Glue Data Catalog stores the metadata and table definitions Athena can use.
Question 2
A company frequently receives new files in an S3 data lake. It wants AWS to inspect the files and automatically create or update table definitions for later Athena queries. Which feature should be selected?
A. An AWS Glue crawler
B. An Athena ORDER BY clause
C. An Amazon RDS read replica
D. A Lambda function without a catalog
Correct answer: A
Explanation: A Glue crawler discovers data and creates or updates tables in the Glue Data Catalog.
Question 3
An Athena query is processing far more data than necessary because it reads every column and scans all files in an S3 dataset. Which change is most directly aligned with the lesson’s optimization guidance?
A. Add more columns to the query
B. Remove all table metadata
C. Partition the data and select only the required columns
D. Move the data to an EC2 instance before querying
Correct answer: C
Explanation: Partitioning can reduce the data scanned, and selecting only needed columns avoids unnecessary processing.
Question 4
An analyst must query information from CloudWatch Logs using Athena. The solution requires a component that connects Athena to the source and maps the data into Athena tables. What should the engineer plan to use?
A. AWS Lambda
B. Amazon RDS Multi-AZ
C. A Glue crawler alone
D. Amazon Redshift Spectrum only
Correct answer: A
Explanation: The lesson identifies Lambda as the integration component for connecting Athena to sources such as CloudWatch Logs and mapping the data into Athena tables.
Question 5
A data engineering team must extract data, transform it for analytics, and load the result into a target data store. Which AWS capability is the best match?
A. Amazon Athena only
B. AWS Glue ETL
C. The AWS Glue Data Catalog only
D. An Athena partition without an ETL job
Correct answer: B
Explanation: AWS Glue is the fully managed ETL service and runs ETL jobs in a managed, scale-out Apache Spark environment.
WordPress Metadata
Suggested Slug:
amazon-athena-aws-glue-querying-cataloging-data
Meta Description:
Study Amazon Athena and AWS Glue for S3 analytics, data cataloging, ETL workflows, crawlers, supported formats, and Athena performance optimization.
Tags:
Amazon Athena, AWS Glue, AWS Certified CloudOps Engineer, Amazon S3, AWS Glue Data Catalog, ETL, Apache Parquet, Apache ORC, AWS Lambda, CloudWatch Logs