Skip to main content

How to query S3 buckets with StackQL

S3 buckets are exposed as two related tables: aws.s3.buckets lists the buckets in the account, and awscc.s3.buckets returns the full configuration of one bucket identified by Identifier. The first is built on the S3 API in the aws provider, the second on the AWS Cloud Control API in the awscc provider.

Prerequisites​

List buckets​

SELECT name, bucket_region, creation_date
FROM aws.s3.buckets
WHERE region = 'us-east-1';

The region predicate is a required routing parameter of the underlying API call; us-east-1 returns the account's buckets.

Inspect one bucket​

The Cloud Control table returns configuration attributes for a named bucket:

SELECT
bucket_name,
bucket_encryption,
versioning_configuration,
public_access_block_configuration
FROM awscc.s3.buckets
WHERE region = 'us-east-1'
AND Identifier = 'my-bucket-name';

Configuration columns return structured JSON; DESCRIBE awscc.s3.buckets lists everything available, including logging_configuration, lifecycle_configuration, object_lock_configuration, tags, and arn.

Audit pattern: enumerate, then inspect​

Account-wide configuration audits combine the two tables: list the bucket names, then query the detail table per bucket. In scripted use (shell loops, or Python via pystackql), iterate over the list result and collect the detail rows - per-bucket checks such as "is versioning enabled?" or "is the public access block complete?" become row predicates over the collected results. This is the documented pattern for S3 inventory in the StackQL AWS tutorials.

Creating buckets​

Writable properties are discoverable the same way readable ones are:

SHOW INSERT INTO awscc.s3.buckets;

This generates an INSERT template covering the resource's writable fields, as the desired-state document Cloud Control takes. Restricting to mandatory fields only is done with the /*+ REQUIRED */ query hint.