S3 桶名不用再抢了:Account Regional Namespaces 来了
用 Amazon S3 最烦的事之一:想好的桶名永远被占。因为桶名全球唯一,热门名字早就没了。
上周亚马逊云科技发了 S3 Account Regional Namespaces。简单说:你的账号有了专属命名空间,桶名只要在你的账号+区域内不重复就行。
桶名格式
{名字}-{账号ID}-{区域}-an
比如 my-data-123456789012-us-east-1-an。别的账号用不了你的后缀。
CLI 创建
aws s3api create-bucket \
--bucket my-data-123456789012-us-east-1-an \
--bucket-namespace account-regional \
--region us-east-1
Python SDK
import boto3
s3 = boto3.client('s3')
sts = boto3.client('sts')
account_id = sts.get_caller_identity()['Account']
region = s3.meta.region_name
bucket_name = f"my-data-{account_id}-{region}-an"
params = {"Bucket": bucket_name, "BucketNamespace": "account-regional"}
if region != "us-east-1":
params["CreateBucketConfiguration"] = {"LocationConstraint": region}
s3.create_bucket(**params)
CloudFormation
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketNamePrefix: 'my-data'
BucketNamespace: 'account-regional'
用 BucketNamePrefix 自动拼接后缀,连账号 ID 都不用写。
安全:强制用新命名空间
新的 condition key s3:x-amz-bucket-namespace,在 IAM 或 SCP 里可以要求所有新桶必须走 account-regional namespace。从组织层面统一管理。
注意事项
- 现有桶不能改名迁移
- 只支持通用桶(Table/Vector/Directory Buckets 已有账号级命名空间)
- 前缀+后缀总共 3-63 字符
- 免费,37 个区域可用
桶名冲突这个老问题终于有了官方解法。新建桶建议直接用。