Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Amazon S3 Tables Construct Library

---

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


Amazon S3 Tables

Amazon S3 Tables deliver the first cloud object store with built-in Apache Iceberg support and streamline storing tabular data at scale.

Product Page | User Guide

Usage

Define an S3 Table Bucket

from aws_cdk.aws_s3tables_alpha import UnreferencedFileRemoval
# Build a Table bucket
sample_table_bucket = TableBucket(scope, "ExampleTableBucket",
    # optional fields:
    table_bucket_name="example-bucket-1",  # if omitted, CDK generates a unique name that satisfies the S3 Tables naming rules
    unreferenced_file_removal=UnreferencedFileRemoval(
        status=UnreferencedFileRemovalStatus.ENABLED,
        noncurrent_days=20,
        unreferenced_days=20
    )
)

When tableBucketName is omitted, CDK derives the name from the stack name and the construct path. Because the path is part of the input, the generated name is not stable across stack or construct renames — renaming or moving the construct will produce a different name and replace the bucket. If you need a fixed, predictable name (for example, to reference the bucket from outside CDK or across separate deployments), pass tableBucketName explicitly.

Define an S3 Tables Namespace

# Build a namespace
sample_namespace = Namespace(scope, "ExampleNamespace",
    namespace_name="example-namespace-1",
    table_bucket=table_bucket
)

Define an S3 Table

from aws_cdk.aws_s3tables_alpha import IcebergMetadataProperty, IcebergSchemaProperty, SchemaFieldProperty, SchemaFieldProperty, CompactionProperty, SnapshotManagementProperty
# Build a table
sample_table = Table(scope, "ExampleTable",
    table_name="example_table",
    namespace=namespace,
    open_table_format=OpenTableFormat.ICEBERG,
    without_metadata=True
)

# Build a table with an Iceberg Schema
sample_table_with_schema = Table(scope, "ExampleSchemaTable",
    table_name="example_table_with_schema",
    namespace=namespace,
    open_table_format=OpenTableFormat.ICEBERG,
    iceberg_metadata=IcebergMetadataProperty(
        iceberg_schema=IcebergSchemaProperty(
            schema_field_list=[SchemaFieldProperty(
                name="id",
                type="int",
                required=True
            ), SchemaFieldProperty(
                name="name",
                type="string"
            )
            ]
        )
    ),
    compaction=CompactionProperty(
        status=Status.ENABLED,
        target_file_size_mb=128
    ),
    snapshot_management=SnapshotManagementProperty(
        status=Status.ENABLED,
        max_snapshot_age_hours=48,
        min_snapshots_to_keep=5
    )
)

Learn more about table buckets maintenance operations and default behavior from the S3 Tables User Guide

Advanced Iceberg Table Configuration

You can configure partition specifications, sort orders, and table properties for optimized query performance.

The simplest way to add partitioning to your table:

from aws_cdk.aws_s3tables_alpha import IcebergMetadataProperty, IcebergSchemaProperty, SchemaFieldProperty, SchemaFieldProperty, IcebergPartitionSpec, IcebergPartitionField
# Build a table with partition spec (minimal configuration)
partitioned_table = Table(scope, "PartitionedTable",
    table_name="partitioned_table",
    namespace=namespace,
    open_table_format=OpenTableFormat.ICEBERG,
    iceberg_metadata=IcebergMetadataProperty(
        iceberg_schema=IcebergSchemaProperty(
            schema_field_list=[SchemaFieldProperty(name="event_date", type="date", required=True), SchemaFieldProperty(name="event_name", type="string")
            ]
        ),
        iceberg_partition_spec=IcebergPartitionSpec(
            fields=[IcebergPartitionField(
                source_id=1,
                transform=IcebergTransform.IDENTITY,
                name="date_partition"
            )
            ]
        )
    )
)

For full control, you can also configure sort orders and table properties:

from aws_cdk.aws_s3tables_alpha import IcebergMetadataProperty, IcebergSchemaProperty, SchemaFieldProperty, SchemaFieldProperty, IcebergPartitionSpec, IcebergPartitionField, IcebergSortOrder, IcebergSortField, TablePropertyEntry
# Build a table with partition spec, sort order, and table properties
advanced_table = Table(scope, "AdvancedTable",
    table_name="advanced_table",
    namespace=namespace,
    open_table_format=OpenTableFormat.ICEBERG,
    iceberg_metadata=IcebergMetadataProperty(
        iceberg_schema=IcebergSchemaProperty(
            schema_field_list=[SchemaFieldProperty(id=1, name="event_date", type="date", required=True), SchemaFieldProperty(id=2, name="user_id", type="string", required=True)
            ]
        ),
        iceberg_partition_spec=IcebergPartitionSpec(
            spec_id=0,
            fields=[IcebergPartitionField(
                source_id=1,
                transform=IcebergTransform.IDENTITY,
                name="date_partition",
                field_id=1000
            )
            ]
        ),
        iceberg_sort_order=IcebergSortOrder(
            order_id=1,
            fields=[IcebergSortField(
                source_id=1,
                transform=IcebergTransform.IDENTITY,
                direction=SortDirection.ASC,
                null_order=NullOrder.NULLS_LAST
            )
            ]
        ),
        table_properties=[TablePropertyEntry(key="write.format.default", value="parquet")
        ]
    )
)

Controlling Table Bucket Permissions

# Grant the principal read permissions to the bucket and all tables within
account_id = "123456789012"
table_bucket.grant_read(iam.AccountPrincipal(account_id), "*")

# Grant the role write permissions to the bucket and all tables within
role = iam.Role(stack, "MyRole", assumed_by=iam.ServicePrincipal("sample"))
table_bucket.grant_write(role, "*")

# Grant the user read and write permissions to the bucket and all tables within
table_bucket.grant_read_write(iam.User(stack, "MyUser"), "*")

# Grant permissions to the bucket and a particular table within it
table_id = "6ba046b2-26de-44cf-9144-0c7862593a7b"
table_bucket.grant_read_write(iam.AccountPrincipal(account_id), table_id)

# Add custom resource policy statements
permissions = iam.PolicyStatement(
    effect=iam.Effect.ALLOW,
    actions=["s3tables:*"],
    principals=[iam.ServicePrincipal("example.aws.internal")],
    resources=["*"]
)

table_bucket.add_to_resource_policy(permissions)

Controlling Table Bucket Encryption Settings

S3 TableBuckets have SSE (server-side encryption with AES-256) enabled by default with S3 managed keys. You can also bring your own KMS key for KMS-SSE or have S3 create a KMS key for you.

If a bucket is encrypted with KMS, grant functions on the bucket will also grant access to the TableBucket's associated KMS key.

# Provide a user defined KMS Key:
key = kms.Key(scope, "UserKey")
encrypted_bucket = TableBucket(scope, "EncryptedTableBucket",
    table_bucket_name="table-bucket-1",
    encryption=TableBucketEncryption.KMS,
    encryption_key=key
)
# This account principal will also receive kms:Decrypt access to the KMS key
encrypted_bucket.grant_read(iam.AccountPrincipal("123456789012"), "*")

# Use S3 managed server side encryption (default)
encrypted_bucket_default = TableBucket(scope, "EncryptedTableBucketDefault",
    table_bucket_name="table-bucket-3",
    encryption=TableBucketEncryption.S3_MANAGED
)

When using KMS encryption (TableBucketEncryption.KMS), if no encryption key is provided, CDK will automatically create a new KMS key for the table bucket with necessary permissions.

# If no key is provided, one will be created automatically
encrypted_bucket_auto = TableBucket(scope, "EncryptedTableBucketAuto",
    table_bucket_name="table-bucket-2",
    encryption=TableBucketEncryption.KMS
)

Enabling CloudWatch Request Metrics

You can enable CloudWatch request metrics for your table bucket. Request metrics provide insight into Amazon S3 Tables requests, helping you monitor and optimize your table bucket usage.

For more information about S3 Tables CloudWatch metrics, see the S3 Tables CloudWatch Metrics documentation.

# Enable CloudWatch request metrics for the table bucket
table_bucket_with_metrics = TableBucket(scope, "TableBucketWithMetrics",
    table_bucket_name="metrics-enabled-bucket",
    request_metrics_status=RequestMetricsStatus.ENABLED
)

Configuring Storage Class

You can configure the storage class for your table bucket and tables. Storage class determines how data is stored and billed, allowing you to optimize for different access patterns.

# Create a table bucket with INTELLIGENT_TIERING storage class
table_bucket_with_storage_class = TableBucket(scope, "TableBucketWithStorageClass",
    table_bucket_name="storage-class-bucket",
    storage_class=StorageClass.INTELLIGENT_TIERING
)

Tables inherit the storage class from their parent bucket by default. You can also override the storage class at the table level:

# Create a table with explicit storage class (overrides bucket default)
table_with_storage_class = Table(scope, "TableWithStorageClass",
    table_name="storage_class_table",
    namespace=namespace,
    open_table_format=OpenTableFormat.ICEBERG,
    without_metadata=True,
    storage_class=StorageClass.STANDARD
)

Available storage classes:

  • StorageClass.STANDARD - For frequently accessed data
  • StorageClass.INTELLIGENT_TIERING - Automatically moves data between access tiers based on usage patterns

Note: Table storage class is a create-only property and cannot be changed after the table is created.

Controlling Table Permissions

# Grant the principal read permissions to the table
account_id = "123456789012"
table.grant_read(iam.AccountPrincipal(account_id))

# Grant the role write permissions to the table
role = iam.Role(stack, "MyRole", assumed_by=iam.ServicePrincipal("sample"))
table.grant_write(role)

# Grant the user read and write permissions to the table
table.grant_read_write(iam.User(stack, "MyUser"))

# Grant an account permissions to the table
table.grant_read_write(iam.AccountPrincipal(account_id))

# Add custom resource policy statements
permissions = iam.PolicyStatement(
    effect=iam.Effect.ALLOW,
    actions=["s3tables:*"],
    principals=[iam.ServicePrincipal("example.aws.internal")],
    resources=["*"]
)

table.add_to_resource_policy(permissions)

Tagging

Both TableBucket and Table support tagging through CDK's standard tagging mechanism:

Tags.of(table_bucket).add("Environment", "Production")
Tags.of(table).add("Team", "DataEngineering")

# Stack-level tags propagate to all resources
Tags.of(stack).add("Project", "DataLake")

Coming Soon

L2 Construct support for:

  • KMS encryption support for Tables

Release files for aws-cdk.aws-s3tables-alpha 2.271.0a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-cdk.aws-s3tables-alpha 2.271.0a0
File Size Uploaded
aws_cdk_aws_s3tables_alpha-2.271.0a0.tar.gz 168.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-cdk.aws-s3tables-alpha 2.271.0a0
File Interpreter ABI Platform
aws_cdk_aws_s3tables_alpha-2.271.0a0-py3-none-any.whl Python 3 none any Details

Total release size: 335.6 kB

Release files / aws_cdk_aws_s3tables_alpha-2.271.0a0.tar.gz

Download URL aws_cdk_aws_s3tables_alpha-2.271.0a0.tar.gz
Size 168.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0da6db1ea30d7e101960f575032f5349af062bf3468ec934ee07d9a5445c6ecb
BLAKE2b-256 checksum
How to use checksums
586d1b74f31792e2671de7e15a663ca86f6610c9edb91d23f989dc4bb2aefd27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / aws_cdk_aws_s3tables_alpha-2.271.0a0-py3-none-any.whl

Download URL aws_cdk_aws_s3tables_alpha-2.271.0a0-py3-none-any.whl
Size 167.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13a373a6cea37651bfbe4c99be23cfa6a98f329761a1db1154fbcc9d0781869b
BLAKE2b-256 checksum
How to use checksums
20af1a4569884af6295371fbe3bcf2767bfd5c430c08d6957f16ff5786ac574a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

2.271.0a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page