Lesson 6 of 8 Amazon Athena and Data Analysis

Controlling Athena Costs with Workgroups and Data Layout

This lesson explains how Athena workgroups separate teams and enforce limits, and how a few layout choices keep every query cheaper, since a single careless query can be expensive.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure workgroups with result locations and encryption.
  • Cap query cost with per-query data usage limits.
  • Choose between on-demand and provisioned capacity pricing.

Workgroups

Workgroups separate teams, applications or environments, each with its own query history, result location, encryption settings and engine version. Separation keeps one team's queries and results apart from another's and lets each be governed differently.

Several controls make workgroups effective for cost and governance. Enforcing workgroup configuration stops users from overriding the workgroup's result location and encryption settings in their own queries. Per-query data usage limits cancel any query that would scan more than a set amount of data, which stops a single careless query from becoming expensive. Workgroup-wide limits track total data scanned over a period and trigger CloudWatch alarms or actions when it passes a threshold. IAM policies can restrict users to specific workgroups, and tags on workgroups allocate their costs to teams.

The following diagram shows the workgroup's controls.

The new team's workgroup. Its IAM permissions allow only this workgroup; the enforced configuration and a per-query data usage limit cancel any query that would scan more than the limit; a workgroup-wide limit raises a CloudWatch alarm; and a cost allocation tag attributes the workgroup's spending to the team.
The tag key and value are illustrative.

Cutting cost

Because on-demand Athena pricing is based on data scanned, most savings come from scanning less. Storing data in columnar, compressed formats such as Parquet and ORC, and selecting only the columns a query needs, reduces the data read from each file. Partitioning, with partition projection for tables with many partitions, lets filters skip whole folders of data.

Usage patterns offer further savings. Query result reuse answers repeated dashboard queries from stored results instead of scanning again. For predictable, heavy workloads, provisioned capacity in DPUs can cost less than paying per terabyte. Federated queries add Lambda connector costs and load on the source system, so data that is queried often should be copied into S3 and queried there instead.

Select all that apply

Cutting Athena cost

Exam skills 1.2.4 · 3.1.7

Identify the practices that cut Athena cost.

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

A company's Athena bill doubled after a new team began exploring data. Some of their queries scan entire multi-terabyte tables. Management wants to cap the cost of any single query from that team and track the team's spending separately.

Create a workgroup for the team with an enforced configuration and a per-query data usage limit, publish its CloudWatch metrics and add a workgroup-wide alarm, tag it for cost allocation, and restrict the team's IAM permissions to that workgroup.

Check yourself

How are users stopped from overriding a workgroup's settings?

Show answer

By enforcing the workgroup configuration.

Exam Tips

Remember for the exam

  • Workgroups isolate teams with their own result locations, encryption, limits and metrics.
  • Per-query limits cancel large scans; workgroup-wide limits alarm on total usage.
  • Enforce workgroup configuration so users cannot override settings.
  • Use result reuse for repeated queries and provisioned capacity for steady heavy use.
  • Parquet, partitions and column selection reduce data scanned.