Skip to content

Commit e8786f5

Browse files
feat(s3tables): add metrics configuration support for TableBucket (#37275)
### Reason for this change This PR adds request metrics configuration support to the S3 Tables TableBucket L2 construct, enabling users to enable or disable CloudWatch request metrics for their table buckets. Request metrics provide insight into Amazon S3 Tables requests, helping users monitor and optimize their table bucket usage. ### Description of changes Enhanced TableBucket construct with request metrics configuration: - Added RequestMetricsStatus enum with ENABLED and DISABLED values - Added requestMetricsStatus property to TableBucketProps (flat structure per CDK guidelines) - Pass metrics configuration through to CfnTableBucket L1 construct Documentation: - Updated README with "Enabling CloudWatch Request Metrics" section - Added RequestMetricsStatus to rosetta fixture ### Description of how you validated changes - Unit tests: added 3 new test cases for request metrics (enabled, disabled, and not specified). All 193 tests passing. - Integration test: created integ.table-bucket-metrics.ts to validate metrics configuration deployment - Rosetta: verified with yarn rosetta:extract - passes successfully ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 093de92 commit e8786f5

15 files changed

Lines changed: 902 additions & 1 deletion

packages/@aws-cdk/aws-s3tables-alpha/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ const encryptedBucketAuto = new TableBucket(scope, 'EncryptedTableBucketAuto', {
235235
});
236236
```
237237

238+
### Enabling CloudWatch Request Metrics
239+
240+
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.
241+
242+
For more information about S3 Tables CloudWatch metrics, see the [S3 Tables CloudWatch Metrics documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-cloudwatch-metrics.html).
243+
244+
```ts
245+
// Enable CloudWatch request metrics for the table bucket
246+
const tableBucketWithMetrics = new TableBucket(scope, 'TableBucketWithMetrics', {
247+
tableBucketName: 'metrics-enabled-bucket',
248+
requestMetricsStatus: RequestMetricsStatus.ENABLED,
249+
});
250+
```
251+
238252
### Controlling Table Permissions
239253

240254
```ts

packages/@aws-cdk/aws-s3tables-alpha/lib/table-bucket.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ export enum UnreferencedFileRemovalStatus {
147147
DISABLED = 'Disabled',
148148
}
149149

150+
/**
151+
* Controls whether CloudWatch request metrics are enabled or disabled for the table bucket.
152+
*/
153+
export enum RequestMetricsStatus {
154+
/**
155+
* Enable CloudWatch request metrics for the table bucket.
156+
*/
157+
ENABLED = 'Enabled',
158+
159+
/**
160+
* Disable CloudWatch request metrics for the table bucket.
161+
*/
162+
DISABLED = 'Disabled',
163+
}
164+
150165
/**
151166
* Controls Server Side Encryption (SSE) for this TableBucket.
152167
*/
@@ -349,6 +364,16 @@ export interface TableBucketProps {
349364
* @default RETAIN
350365
*/
351366
readonly removalPolicy?: RemovalPolicy;
367+
368+
/**
369+
* CloudWatch request metrics configuration for the table bucket.
370+
*
371+
* When enabled, S3 Tables publishes CloudWatch request metrics for the table bucket.
372+
* Request metrics provide insight into Amazon S3 Tables requests.
373+
*
374+
* @default - Request metrics are disabled
375+
*/
376+
readonly requestMetricsStatus?: RequestMetricsStatus;
352377
}
353378

354379
/**
@@ -601,6 +626,7 @@ export class TableBucket extends TableBucketBase {
601626
unreferencedDays: props.unreferencedFileRemoval?.unreferencedDays,
602627
},
603628
encryptionConfiguration: bucketEncryption,
629+
metricsConfiguration: props.requestMetricsStatus ? { status: props.requestMetricsStatus } : undefined,
604630
});
605631

606632
this.resource.applyRemovalPolicy(props.removalPolicy);

packages/@aws-cdk/aws-s3tables-alpha/rosetta/default.ts-fixture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Construct } from 'constructs';
22
import { Stack } from 'aws-cdk-lib';
3-
import { TableBucket, UnreferencedFileRemovalStatus, TableBucketEncryption, Namespace, Table, Status, OpenTableFormat, IcebergTransform, SortDirection, NullOrder } from '@aws-cdk/aws-s3tables-alpha';
3+
import { TableBucket, UnreferencedFileRemovalStatus, TableBucketEncryption, RequestMetricsStatus, Namespace, Table, Status, OpenTableFormat, IcebergTransform, SortDirection, NullOrder } from '@aws-cdk/aws-s3tables-alpha';
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
import * as kms from 'aws-cdk-lib/aws-kms';
66

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/MetricsEnabledTestStack.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/MetricsEnabledTestStack.metadata.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Resources": {
3+
"MetricsEnabledBucket01C9F646": {
4+
"Type": "AWS::S3Tables::TableBucket",
5+
"Properties": {
6+
"MetricsConfiguration": {
7+
"Status": "Enabled"
8+
},
9+
"TableBucketName": "metrics-enabled-test-bucket",
10+
"UnreferencedFileRemoval": {}
11+
},
12+
"UpdateReplacePolicy": "Delete",
13+
"DeletionPolicy": "Delete"
14+
}
15+
},
16+
"Parameters": {
17+
"BootstrapVersion": {
18+
"Type": "AWS::SSM::Parameter::Value<String>",
19+
"Default": "/cdk-bootstrap/hnb659fds/version",
20+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
21+
}
22+
},
23+
"Rules": {
24+
"CheckBootstrapVersion": {
25+
"Assertions": [
26+
{
27+
"Assert": {
28+
"Fn::Not": [
29+
{
30+
"Fn::Contains": [
31+
[
32+
"1",
33+
"2",
34+
"3",
35+
"4",
36+
"5"
37+
],
38+
{
39+
"Ref": "BootstrapVersion"
40+
}
41+
]
42+
}
43+
]
44+
},
45+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
46+
}
47+
]
48+
}
49+
}
50+
}

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/TableBucketMetricsIntegTestDefaultTestDeployAssertD1D86737.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/TableBucketMetricsIntegTestDefaultTestDeployAssertD1D86737.metadata.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/TableBucketMetricsIntegTestDefaultTestDeployAssertD1D86737.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.table-bucket-metrics.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)