Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AWS with AI Difficulty: Advanced ClaudeChatGPTCursor

AWS Athena and Glue Query Cost Optimization Prompt

Cut Amazon Athena data-scanned cost and speed up queries by partitioning, converting to columnar formats, compacting small files, and fixing Glue Data Catalog table design without changing query semantics.

Target user
Data and platform engineers running Athena over S3 data lakes
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior AWS analytics engineer who optimizes Athena query cost and performance over an S3 data lake.

I will provide:
- The problem queries (SQL) and their reported Data Scanned / runtime from the Athena console or query stats
- The table DDL (or Glue Catalog details): storage format, partition keys, S3 layout, and approximate object count/sizes
- How data lands (streaming, hourly batch, CDC) and whether the small-files problem exists
- Constraints: query patterns that must keep working, freshness requirements, and whether Iceberg/partition projection is on the table

Your job:

1. **Attribute the cost** — for each query, explain what drives the bytes scanned (no partition pruning, `SELECT *`, row-based CSV/JSON, tiny files, unpruned predicates) using the EXPLAIN plan and scan stats.
2. **Partition and prune** — recommend partition keys aligned to the WHERE clauses, enable partition projection or `MSCK`/partition management, and rewrite predicates so pruning actually engages.
3. **Convert to columnar** — propose Parquet/ORC with appropriate compression (ZSTD/Snappy) and column ordering, and quantify the expected scan reduction vs the conversion cost.
4. **Fix small files** — design compaction (target 128–512 MB objects) via CTAS/INSERT INTO or a Glue job, and prevent recurrence at ingest.
5. **Rewrite the queries** — project only needed columns, push down filters, avoid cross-joins and needless DISTINCT, and use approximate functions where exactness is not required.
6. **Add cost guardrails** — set workgroup per-query and per-workgroup data-scan limits, and describe how to verify the before/after bytes scanned and dollar impact.

Output: (a) a per-query diagnosis with the scan-cost driver, (b) the new table DDL / partition-projection config, (c) the compaction/conversion job outline, and (d) the rewritten SQL with an estimated bytes-scanned and cost delta plus a validation step (row-count parity).

Advise only: produce DDL, jobs, and SQL for me to review and run against a copy first. Do not assume it is safe to overwrite production tables or S3 prefixes.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More AWS with AI prompts & error guides

Browse every AWS with AI prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.