Query AWS S3 System Tables
Overview
Works best with the AWS MCP server for sandboxed execution and audit logging. All commands below use the AWS CLI and work in any environment with configured AWS credentials. Use IAM roles or temporary credentials; avoid long-lived access keys.
Amazon S3 Metadata provides continuously-updated Apache Iceberg tables that capture
object-level metadata for general-purpose buckets. S3 Storage Lens exports aggregated
storage and activity metrics as Iceberg tables. Both are read-only, stored in the
AWS-managed aws-s3 table bucket, and queryable via Amazon Athena.
System tables are preferred over raw S3 APIs (list-objects-v2, head-object) because:
list-objects-v2paginates at 1000 objects/page — inefficient for large buckets (millions or billions of objects). The inventory table answersSELECT COUNT(*)in seconds at any scale.list-objects-v2cannot identify who uploaded an object, from which IP, or when something was deleted. Only the journal table hasrequester,source_ip_address, and delete event tracking.- Filtering by tag requires
get-object-taggingper object. The inventory table hasobject_tagsas a queryable map column.
Decision Tree
Common Tasks
1. Check If Configured
Before querying, confirm S3 Metadata is enabled on the target bucket.
Interpret the response:
MetadataConfigurationNotFounderror → not enabled. See Enable section below.TableStatus: ACTIVE→ ready to query.TableStatus: BACKFILLING→ queryable but inventory may be incomplete.TableStatus: FAILED→ check error field (usually IAM).
For Storage Lens:
Look for DataExport.StorageLensTableDestination.IsEnabled: true.
2. Enable (if not configured)
Enable S3 Metadata on a bucket:
To also enable annotations (requires a service role):
Enable Storage Lens S3 Tables export:
Register S3 Tables federated catalog in Glue (required for Athena access):
For setup permissions and IAM role requirements, see Security Considerations below.
3. Verify Permissions
Querying requires:
- Athena execution permissions
- S3 Tables read permissions (see least-privilege policy in Security Considerations)
- The S3 Tables federated catalog registered in Glue (
s3tablescatalog) - Athena workgroup with SSE-KMS encryption configured on the output location
If CATALOG_NOT_FOUND errors occur, the Glue integration may not be enabled. See:
Integrating S3 Tables with AWS analytics services
4. Identify the Target Table
S3 Metadata tables — namespace is b_<bucket-name>:
Storage Lens tables — namespace is lens_<config-id>_exp:
5. Query
Query syntax:
Constraints:
-
You MUST confirm workgroup and output location before executing
-
You MUST ensure the Athena workgroup enforces SSE-KMS encryption on query results
-
You MUST warn user that tables are read-only — no INSERT/UPDATE/DELETE
-
You SHOULD use the key columns documented in this skill to build queries. If you need the full schema (e.g., AWS has added new columns), run
get-tablesonce on any single namespace — schemas are identical across all instances of the same table type:
Journal — audit who changed what:
Journal — track annotation events:
Inventory — find objects by storage class:
Inventory — find objects by tag:
Annotation — search across payloads:
Annotation — extract JSON fields:
Storage Lens — storage distribution:
Routing: Athena vs Direct API
Troubleshooting
Security Considerations
Least-Privilege IAM Policy
Scope permissions to specific table bucket ARNs rather than using wildcards:
Data Sensitivity
Journal query results may contain sensitive fields:
requester— AWS account ID or service principal that made the requestsource_ip_address— IP address of the requester
Query results containing these fields should be stored in encrypted, access-controlled locations. Avoid logging or sharing raw query output that contains IP addresses or principal identifiers.
Encryption for Query Results
Configure the Athena workgroup with EncryptionConfiguration to encrypt query results at rest:
Audit Trail
Enable CloudTrail logging for Athena (StartQueryExecution, GetQueryResults) and S3 Tables (s3tables:GetTableData) API calls to maintain an audit trail of who queried what metadata. Ensure CloudTrail logs are encrypted with SSE-KMS and stored in a bucket with access logging enabled.
