Skip to content

feat(s3tables): make tableBucketName optional on TableBucket#37749

Open
badmintoncryer wants to merge 4 commits into
aws:mainfrom
badmintoncryer:feat/s3tables-optional-table-bucket-name-clean
Open

feat(s3tables): make tableBucketName optional on TableBucket#37749
badmintoncryer wants to merge 4 commits into
aws:mainfrom
badmintoncryer:feat/s3tables-optional-table-bucket-name-clean

Conversation

@badmintoncryer
Copy link
Copy Markdown
Contributor

@badmintoncryer badmintoncryer commented May 3, 2026

Issue # (if applicable)

Closes #37747.

Reason for this change

@aws-cdk/aws-s3tables-alpha's TableBucket requires tableBucketName as a mandatory prop, which is inconsistent with aws-s3.Bucket and the majority of CDK L2 constructs where the resource name is optional. Forcing every caller to invent a globally-unique name is friction that does not exist for Bucket and other comparable resources.

Description of changes

  • TableBucketProps.tableBucketName is now string? (optional). Existing code that passes tableBucketName is unaffected.
  • When the user omits tableBucketName, the constructor generates a unique name via:
    Lazy.string({
      produce: () => Names.uniqueResourceName(this, {
        maxLength: 63,
        allowedSpecialCharacters: '-',
        separator: '-',
      }).toLowerCase(),
    })
    The result satisfies the S3 Tables naming rules (3-63 chars, lowercase letters / digits / hyphens, alphanumeric at start and end). Sample produced name from the new integ stack: autonamedteststack-autonamedbucket-ab3a2b45.
  • The L1 CfnTableBucket now receives this.physicalName (instead of props.tableBucketName), so user-supplied and auto-generated paths are unified. This is the same pattern as aws-s3.Bucket (bucketName: this.physicalName).

Why Lazy.string + Names.uniqueResourceName and not PhysicalName.GENERATE_IF_NEEDED?

AWS::S3Tables::TableBucket requires TableBucketName per the CFN spec (see cdk.requiredValidator in the generated L1). PhysicalName.GENERATE_IF_NEEDED only triggers generatePhysicalName() for cross-environment references; for same-env usage it leaves the name as undefined, which fails L1 synthesis. We therefore need eager generation. The Lazy.string + Names.uniqueResourceName pattern is exactly what other L2s in this situation use:

L2 Source
aws-elasticloadbalancingv2.TrustStore packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/trust-store.ts
aws-cloudfront.RealtimeLogConfig packages/aws-cdk-lib/aws-cloudfront/lib/realtime-log-config.ts
aws-cloudfront.KeyValueStore packages/aws-cdk-lib/aws-cloudfront/lib/key-value-store.ts

Describe any new or updated permissions being added

None.

Description of how you validated changes

Add both unit and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Aligns the `TableBucket` L2 with `aws-s3.Bucket` and most other CDK L2s
where the resource name is optional. When `tableBucketName` is not
provided, CDK now generates a unique name from the stack name and
construct path that satisfies the S3 Tables naming rules (3-63 chars,
lowercase letters/digits/hyphens, alphanumeric edges).

The underlying `AWS::S3Tables::TableBucket` requires `TableBucketName`
in the CFN spec, so name generation happens on the CDK side via
`Names.uniqueResourceName` wrapped in `Lazy.string`, mirroring the
pattern already used by `TrustStore`, `RealtimeLogConfig`, and
`KeyValueStore`.

Backwards compatible: existing code passing `tableBucketName` is
unaffected.

closes aws#37747
@github-actions github-actions Bot added the p2 label May 3, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team May 3, 2026 02:30
@github-actions github-actions Bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

Mix the optional-name note inline as a comment on the
tableBucketName field (drops the standalone paragraph and the
extra auto-named example). Drop unit tests that asserted
naming-rule regex, no-throw, and the cross-env ARN path —
those are covered by the integ assertion and the existing
distinct-name test.
@badmintoncryer badmintoncryer marked this pull request as ready for review May 3, 2026 03:28
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label May 3, 2026
…ross renames

Address review feedback on aws#37747: clarify in the README and the
`tableBucketName` JSDoc that the auto-generated name derives from the
construct path, so renaming the stack or construct produces a different
name and replaces the bucket. Users who need a stable identifier should
pass `tableBucketName` explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s3tables: make tableBucketName optional on TableBucket L2

2 participants