Amazon.CDK.AWS.S3Tables.Alpha
CDK Constructs for S3 Tables (Stability: Experimental)
Install
| Product | Versions |
|---|---|
| .NET |
README
Amazon S3 Tables Construct Library
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.
Usage
Define an S3 Table Bucket
// Build a Table bucket
var sampleTableBucket = new TableBucket(scope, "ExampleTableBucket", new TableBucketProps {
// optional fields:
TableBucketName = "example-bucket-1", // if omitted, CDK generates a unique name that satisfies the S3 Tables naming rules
UnreferencedFileRemoval = new UnreferencedFileRemoval {
Status = UnreferencedFileRemovalStatus.ENABLED,
NoncurrentDays = 20,
UnreferencedDays = 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
var sampleNamespace = new Namespace(scope, "ExampleNamespace", new NamespaceProps {
NamespaceName = "example-namespace-1",
TableBucket = tableBucket
});
Define an S3 Table
// Build a table
var sampleTable = new Table(scope, "ExampleTable", new TableProps {
TableName = "example_table",
Namespace = namespace,
OpenTableFormat = OpenTableFormat.ICEBERG,
WithoutMetadata = true
});
// Build a table with an Iceberg Schema
var sampleTableWithSchema = new Table(scope, "ExampleSchemaTable", new TableProps {
TableName = "example_table_with_schema",
Namespace = namespace,
OpenTableFormat = OpenTableFormat.ICEBERG,
IcebergMetadata = new IcebergMetadataProperty {
IcebergSchema = new IcebergSchemaProperty {
SchemaFieldList = new [] { new SchemaFieldProperty {
Name = "id",
Type = "int",
Required = true
}, new SchemaFieldProperty {
Name = "name",
Type = "string"
} }
}
},
Compaction = new CompactionProperty {
Status = Status.ENABLED,
TargetFileSizeMb = 128
},
SnapshotManagement = new SnapshotManagementProperty {
Status = Status.ENABLED,
MaxSnapshotAgeHours = 48,
MinSnapshotsToKeep = 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:
// Build a table with partition spec (minimal configuration)
var partitionedTable = new Table(scope, "PartitionedTable", new TableProps {
TableName = "partitioned_table",
Namespace = namespace,
OpenTableFormat = OpenTableFormat.ICEBERG,
IcebergMetadata = new IcebergMetadataProperty {
IcebergSchema = new IcebergSchemaProperty {
SchemaFieldList = new [] { new SchemaFieldProperty { Name = "event_date", Type = "date", Required = true }, new SchemaFieldProperty { Name = "event_name", Type = "string" } }
},
IcebergPartitionSpec = new IcebergPartitionSpec {
Fields = new [] { new IcebergPartitionField {
SourceId = 1,
Transform = IcebergTransform.IDENTITY,
Name = "date_partition"
} }
}
}
});
For full control, you can also configure sort orders and table properties:
// Build a table with partition spec, sort order, and table properties
var advancedTable = new Table(scope, "AdvancedTable", new TableProps {
TableName = "advanced_table",
Namespace = namespace,
OpenTableFormat = OpenTableFormat.ICEBERG,
IcebergMetadata = new IcebergMetadataProperty {
IcebergSchema = new IcebergSchemaProperty {
SchemaFieldList = new [] { new SchemaFieldProperty { Id = 1, Name = "event_date", Type = "date", Required = true }, new SchemaFieldProperty { Id = 2, Name = "user_id", Type = "string", Required = true } }
},
IcebergPartitionSpec = new IcebergPartitionSpec {
SpecId = 0,
Fields = new [] { new IcebergPartitionField {
SourceId = 1,
Transform = IcebergTransform.IDENTITY,
Name = "date_partition",
FieldId = 1000
} }
},
IcebergSortOrder = new IcebergSortOrder {
OrderId = 1,
Fields = new [] { new IcebergSortField {
SourceId = 1,
Transform = IcebergTransform.IDENTITY,
Direction = SortDirection.ASC,
NullOrder = NullOrder.NULLS_LAST
} }
},
TableProperties = new [] { new TablePropertyEntry { Key = "write.format.default", Value = "parquet" } }
}
});
Controlling Table Bucket Permissions
// Grant the principal read permissions to the bucket and all tables within
var accountId = "123456789012";
tableBucket.GrantRead(new AccountPrincipal(accountId), "*");
// Grant the role write permissions to the bucket and all tables within
var role = new Role(stack, "MyRole", new RoleProps { AssumedBy = new ServicePrincipal("sample") });
tableBucket.GrantWrite(role, "*");
// Grant the user read and write permissions to the bucket and all tables within
tableBucket.GrantReadWrite(new User(stack, "MyUser"), "*");
// Grant permissions to the bucket and a particular table within it
var tableId = "6ba046b2-26de-44cf-9144-0c7862593a7b";
tableBucket.GrantReadWrite(new AccountPrincipal(accountId), tableId);
// Add custom resource policy statements
var permissions = new PolicyStatement(new PolicyStatementProps {
Effect = Effect.ALLOW,
Actions = new [] { "s3tables:*" },
Principals = new [] { new ServicePrincipal("example.aws.internal") },
Resources = new [] { "*" }
});
tableBucket.AddToResourcePolicy(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:
var key = new Key(scope, "UserKey", new KeyProps { });
var encryptedBucket = new TableBucket(scope, "EncryptedTableBucket", new TableBucketProps {
TableBucketName = "table-bucket-1",
Encryption = TableBucketEncryption.KMS,
EncryptionKey = key
});
// This account principal will also receive kms:Decrypt access to the KMS key
encryptedBucket.GrantRead(new AccountPrincipal("123456789012"), "*");
// Use S3 managed server side encryption (default)
var encryptedBucketDefault = new TableBucket(scope, "EncryptedTableBucketDefault", new TableBucketProps {
TableBucketName = "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
var encryptedBucketAuto = new TableBucket(scope, "EncryptedTableBucketAuto", new TableBucketProps {
TableBucketName = "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
var tableBucketWithMetrics = new TableBucket(scope, "TableBucketWithMetrics", new TableBucketProps {
TableBucketName = "metrics-enabled-bucket",
RequestMetricsStatus = 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
var tableBucketWithStorageClass = new TableBucket(scope, "TableBucketWithStorageClass", new TableBucketProps {
TableBucketName = "storage-class-bucket",
StorageClass = 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)
var tableWithStorageClass = new Table(scope, "TableWithStorageClass", new TableProps {
TableName = "storage_class_table",
Namespace = namespace,
OpenTableFormat = OpenTableFormat.ICEBERG,
WithoutMetadata = true,
StorageClass = StorageClass.STANDARD
});
Available storage classes:
StorageClass.STANDARD- For frequently accessed dataStorageClass.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
var accountId = "123456789012";
table.GrantRead(new AccountPrincipal(accountId));
// Grant the role write permissions to the table
var role = new Role(stack, "MyRole", new RoleProps { AssumedBy = new ServicePrincipal("sample") });
table.GrantWrite(role);
// Grant the user read and write permissions to the table
table.GrantReadWrite(new User(stack, "MyUser"));
// Grant an account permissions to the table
table.GrantReadWrite(new AccountPrincipal(accountId));
// Add custom resource policy statements
var permissions = new PolicyStatement(new PolicyStatementProps {
Effect = Effect.ALLOW,
Actions = new [] { "s3tables:*" },
Principals = new [] { new ServicePrincipal("example.aws.internal") },
Resources = new [] { "*" }
});
table.AddToResourcePolicy(permissions);
Tagging
Both TableBucket and Table support tagging through CDK's standard tagging mechanism:
Tags.Of(tableBucket).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
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.