Skip to content

Commit ee25970

Browse files
committed
Auto-detect account regional namespace buckets in s3 mb and set BucketNamespace header
1 parent 5d519db commit ee25970

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

awscli/customizations/s3/subcommands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from awscli.customizations.s3.utils import find_bucket_key, AppendFilter, \
3232
find_dest_path_comp_key, human_readable_size, \
3333
RequestParamsMapper, split_s3_bucket_key, block_unsupported_resources, \
34-
S3PathResolver
34+
S3PathResolver, is_account_regional_namespace_bucket
3535
from awscli.customizations.utils import uni_print
3636
from awscli.customizations.s3.syncstrategy.base import MissingFileSync, \
3737
SizeAndLastModifiedSync, NeverSync, AlwaysSync
@@ -910,6 +910,9 @@ def _run_main(self, parsed_args, parsed_globals):
910910
bucket_config = {}
911911
bucket_tags = self._create_bucket_tags(parsed_args)
912912

913+
if is_account_regional_namespace_bucket(bucket):
914+
params['BucketNamespace'] = 'account-regional'
915+
913916
# Only set LocationConstraint when the region name is not us-east-1.
914917
# Sending LocationConstraint with value us-east-1 results in an error.
915918
if self.client.meta.region_name != 'us-east-1':

awscli/customizations/s3/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@
5858
r'[a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$'
5959
)
6060

61+
_S3_ACCOUNT_REGIONAL_NAMESPACE_REGEX = re.compile(
62+
r'^.+-\d{12}-[a-z]{2}(-[a-z]+-\d+)?-an$'
63+
)
64+
6165
_S3_OBJECT_LAMBDA_TO_BUCKET_KEY_REGEX = re.compile(
6266
r'^(?P<bucket>arn:(aws).*:s3-object-lambda:[a-z\-0-9]+:[0-9]{12}:'
6367
r'accesspoint[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$'
6468
)
6569

6670

71+
def is_account_regional_namespace_bucket(bucket):
72+
return bool(_S3_ACCOUNT_REGIONAL_NAMESPACE_REGEX.match(bucket))
73+
74+
6775
def human_readable_size(value):
6876
"""Convert a size in bytes into a human readable format.
6977

0 commit comments

Comments
 (0)