Querying data lake

From aws/agent-toolkit-for-aws · View interactive version

Querying data lake is an AI agent skill from the GitHub repository aws/agent-toolkit-for-aws. Execute and manage Athena SQL queries across default and federated catalogs (Glue, S3 Tables, Redshift). Triggers on phrases like: query data, run SQL, athena query, analyze table, SQL query, workgroup status, profile table, query Redshift catalog, query S3 Tables. Do NOT use for finding specific da

How to use this skill

Skill file

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:

Common Tasks

1. Verify Dependencies

Check for required tools and AWS access before running queries.

Constraints:

2. Resolve Workgroup

Check caller identity, list workgroups, auto-select the best one (see workgroup-selection.md).

Constraints:

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:

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:

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:

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:

  1. Contains SQL keywords (SELECT, SHOW, DESCRIBE, INSERT, etc.) — SQL text, execute directly
  2. profile TABLE_NAME — run comprehensive table profiling (see query-patterns.md)
  3. Matches a known named query — look up and execute
  4. Matches a known workgroup — show workgroup status and recent queries
  5. Matches a known catalog — delegate to exploring-data-catalog to enumerate databases and tables
  6. No args — show recent query activity and available tables

Principles

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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.