Querying Data Lake
AWSOfficialPublished by AWS
- Skill
- Tool integration
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured interface for running SQL queries on Amazon Athena. It handles the complexities of multi-catalog environments, including Glue, S3 Tables, and Redshift. The skill emphasizes safe execution by classifying SQL statements, enforcing workgroup selection, and providing cost and performance insights. It integrates with AWS infrastructure to ensure queries are executed within the correct context, while providing clear error recovery paths and guidance on table profiling.
What it does
- Executes SQL queries on Amazon Athena across various catalog types.
- Automatically selects appropriate workgroups based on IAM identity and project context.
- Classifies SQL statements to identify and warn about destructive operations.
- Profiles tables to provide schema discovery and sample data before analytical queries.
- Reports query cost, data scanned, and execution duration.
- Handles federated query configurations for Redshift and S3 Tables.
When to use it
- When you need to run ad-hoc SQL queries against data stored in S3 via Athena.
- When working in environments with multiple federated catalogs like Glue or Redshift.
- When you need to perform exploratory data analysis or profile unfamiliar tables.
- When you require a safe, audited way to execute SQL that tracks costs and performance.
Advantages
- Prevents common errors by enforcing workgroup selection and output location verification.
- Reduces risk by classifying and requiring confirmation for destructive SQL statements.
- Simplifies complex multi-catalog addressing for Glue, Redshift, and S3 Tables.
- Provides built-in cost awareness and performance metrics for every query.
- Integrates with AWS MCP for secure, sandboxed execution and logging.
Usage examples
- “Run a SQL query to count total users from the sales table.”
- The agent identifies the target table, selects the appropriate workgroup, executes the count query, and returns the result with cost and data scanned metrics.
- “Profile the customer_data table.”
- The agent runs schema discovery, provides a row count, and displays sample rows to help you understand the table structure.
- “Query the Redshift federated catalog for recent transactions.”
- The agent configures the execution context for the Redshift catalog, warns about potential full-table scans, and executes the query.
- “What is the status of my current workgroup?”
- The agent displays the current workgroup configuration, its output location, and recent query activity.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/aws/querying-data-lake/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip querying-data-lake.zip -d .agents/skills
Documentation by AWS
Query Data Lake
Execute SQL queries on Amazon Athena across default and federated catalogs (Glue, S3 Tables, Redshift) with workgroup selection, statement classification, and error recovery.
Overview
Executes and manages Athena SQL queries across default and federated catalogs. Selects a workgroup, resolves target assets (delegating fuzzy references to finding-data-lake-assets), classifies statements for safety, and reports cost and data scanned. Use the AWS MCP server for sandboxed execution and audit logging; the same AWS CLI commands work directly when the MCP server is not available.
Constraints for parameter acquisition:
You MUST accept a single optional argument: SQL text, a named-query name, a workgroup name, a catalog name, or
profile TABLE_NAMEYou MUST accept the argument as direct text or a pointer to a file containing SQL
You MUST ask the user for the target AWS region if not already set
You MUST confirm the output S3 location before executing any non-trivial query
You MUST respect the user's decision to abort at any step
Common Tasks
1. Verify Dependencies
Check for required tools and AWS access before running queries.
Constraints:
You MUST verify AWS MCP server tools are available (
aws___call_aws) and run queries through them when present; fall back to AWS CLI only if the MCP server is unavailableYou MUST NOT fall back to shell or Bash for query execution — results must be captured via the MCP tool or
aws athenaCLI so output location and cost are trackedYou MUST confirm credentials with
aws sts get-caller-identityand inform the user about any missing tools
2. Resolve Workgroup
Check caller identity, list workgroups, auto-select the best one (see workgroup-selection.md).
Constraints:
You MUST select a workgroup before submitting any query (prevents output-location errors)
You MUST present the selected workgroup and its output location to the user
You MUST NOT auto-escalate to a different workgroup on failure without user confirmation
3. Resolve the Target Asset
If the user refers to a table by name, by business concept ("our quarterly report", "the sales data"), by S3 path, or by catalog without specifying the table, delegate to finding-data-lake-assets to return the concrete database.table (and catalog if non-default).
Constraints:
You MUST NOT attempt to resolve fuzzy asset references with
athena list-data-catalogsor by iteratingget-tables— those miss federated catalogs and waste tokensYou SHOULD skip this step only when the user provides a fully-qualified reference (exact
database.table) or raw SQL they want executed as-isYou MUST state the resolved asset explicitly before building the query: "Found [table] in [catalog]. Using this for the query."
You SHOULD default to the default Glue catalog unless the user mentions "federated", "Redshift", "S3 Tables", or
finding-data-lake-assetsreturns a different catalog
4. Discover Schema
For analytical queries, You SHOULD profile the target table before building the final query. You MUST show sample rows (SELECT ... LIMIT 5) as part of profiling.
5. Build Query
Table addressing depends on catalog type:
Default Glue catalog:
database.table(omit the catalog prefix for single-catalog queries). In cross-catalog queries, qualify default-catalog tables with"awsdatacatalog".database.table.Registered data source:
datasource.database.tableUnregistered Glue catalog:
"catalog/subcatalog".database.table
6. Classify and Execute
Classify the SQL statement before executing:
| Statement | Behavior |
|---|---|
SELECT, SHOW, DESCRIBE, EXPLAIN | Safe — execute |
INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, TRUNCATE, MERGE | Destructive — warn the user and require explicit confirmation |
| Unsure | Treat as destructive; confirm |
Example tool call (via AWS MCP server):
aws___call_aws(command="aws athena start-query-execution --work-group <WORKGROUP_NAME> --query-string '<sql>' --query-execution-context Database=<db>")For federated or S3 Tables catalogs, also set Catalog=<CATALOG_PATH> in the execution context (e.g. Catalog=s3tablescatalog/<BUCKET_NAME>).
Constraints:
You MUST warn the user before executing when the target is Redshift-federated ("No partition pruning — every query scans the full table")
You MUST warn the user before executing a cross-catalog join ("Cross-catalog joins incur network overhead and may be slow")
You MUST confirm the output S3 location before executing
You MUST explain which tool is being called before executing
You MUST respect the user's decision to abort
7. Present and Recover
Present results with cost, data scanned, duration, and actionable insights. On failure, list available workgroups and let the user choose which to retry with.
Argument Routing
Resolve in this order; stop at the first match:
Contains SQL keywords (
SELECT,SHOW,DESCRIBE,INSERT, etc.) — SQL text, execute directlyprofile TABLE_NAME— run comprehensive table profiling (see query-patterns.md)Matches a known named query — look up and execute
Matches a known workgroup — show workgroup status and recent queries
Matches a known catalog — delegate to
exploring-data-catalogto enumerate databases and tablesNo args — show recent query activity and available tables
Principles
Always select workgroup before executing (prevents output-location errors)
Profile unfamiliar tables before running analytical queries
Present cost alongside results so users build cost awareness
Suggest
LIMITfor exploratory queries on large tablesNever ask domain questions with obvious answers, but always confirm security-relevant actions (workgroup switches, output location changes, non-SELECT statements)
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
| Redshift identifier error with mixed case | Redshift-federated names are lowercase only | Lowercase the identifier |
CatalogId validation failure | ARN passed instead of catalog name | Pass the catalog name, not the ARN |
Cross-catalog information_schema returns nothing | Missing catalog qualifier | Use catalog-qualified path: "catalog".information_schema.tables |
| Query fails with output-location error | Workgroup has no output location configured | Select a different workgroup with an output location, or configure one |
| Destructive statement executed without confirmation | Statement classification skipped | Always classify INSERT/UPDATE/DELETE/DROP/ALTER/CREATE/TRUNCATE/MERGE and confirm with the user |
Additional Resources
Files
- ATTRIBUTION.mdAdded by AutoGineer916 B
- LICENSELicence file added by AutoGineer9.9 KiB
- NOTICELicence file added by AutoGineer67 B
- SKILL.md7.6 KiB
- references/query-patterns.md4.9 KiB
- references/workgroup-selection.md3.9 KiB
NOTICE
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- AWS
- Publisher
- AWS (Official)
- Source
- aws/agent-toolkit-for-aws · plugins/aws-data-analytics/skills/querying-data-lake · commit 0a218f8
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- NOTICE (added by AutoGineer from NOTICE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Also distributed in
- aws/agent-toolkit-for-aws
AutoGineer is not affiliated with or endorsed by AWS.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download querying-data-lake.zip