feat(s3): support bucketNamePrefix and bucketNamespace properties#37386
Open
feat(s3): support bucketNamePrefix and bucketNamespace properties#37386
bucketNamePrefix and bucketNamespace properties#37386Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
N/A
Reason for this change
The L1
AWS::S3::Bucketresource addedBucketNamePrefixandBucketNamespaceproperties, enabling account-regional bucket naming. AWS recommends creating new S3 buckets in the account-regional namespace, as bucket names are scoped to the account and region, reducing the risk of name conflicts and preventing other accounts from claiming the same name. This is particularly useful for anyone creating new S3 buckets. The L2Bucketconstruct should expose these new properties.Description of changes
bucketNamePrefixandbucketNamespaceprops toBucketPropsBucketNamespaceenum (GLOBAL,ACCOUNT_REGIONAL)bucketName+bucketNamePrefix→ error (mutually exclusive)bucketName+bucketNamespace(exceptGLOBAL) → error (usebucketNamePrefixwithbucketNamespaceinstead)bucketNamePrefixwithoutbucketNamespace: ACCOUNT_REGIONAL→ error (prefix requires account-regional namespace)bucketNamespace: ACCOUNT_REGIONALwithoutbucketNamePrefix→ error (account-regional namespace requires a prefix)bucketNamePrefixandbucketNamespacethrough to theCfnBucketresourceDesign decisions:
Although CloudFormation allows
bucketNamewithbucketNamespace: account-regional, this is functionally equivalent to specifyingbucketNamePrefixwithaccount-regionalnamespace. Supporting both paths would increase validation complexity for no practical benefit, and AWS recommends usingbucketNamePrefixfor account-regional buckets. Therefore,bucketName+bucketNamespaceis treated as an error.The maximum prefix length is validated at 37 characters. The account-regional suffix format is
-<accountId(12)>-<region>-an, and the S3 bucket name limit is 63 characters. The suffix length varies by region name length; 37 is the maximum prefix length for the shortest region code (us-east-1, 9 chars → 26-char suffix). Longer region codes (e.g.ap-northeast-1) will have a shorter effective limit, which CloudFormation enforces at deploy time.When
bucketNamespace: account-regionalis specified withoutbucketNameorbucketNamePrefix, CloudFormation's auto-generated bucket name does not include the required account-regional suffix (-<accountId>-<region>-an), causing the S3 API to reject the request:Resource handler returned message: "The requested bucket name did not include the account-regional namespace suffix, but the provided x-amz-bucket-namespace header value is account-regional. Specify -[accountId]-[region]-an as the bucket name suffix to create a bucket in your account-regional namespace, or remove the header. (Service: S3, Status Code: 400)"
Therefore, the L2 construct validates that
bucketNamePrefixis required whenbucketNamespaceisACCOUNT_REGIONAL, failing early with a clear error message rather than deferring to a CloudFormation deployment failure. This means that for account-regional buckets, users must explicitly specify abucketNamePrefixrather than relying on CloudFormation's recommended auto-generated naming.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