673673 ),
674674}
675675
676+ TAGS = {
677+ 'name' : 'tags' ,
678+ 'synopsis' : '--tags <key> <value>' ,
679+ 'action' : 'append' ,
680+ 'nargs' : 2 ,
681+ 'help_text' : (
682+ 'This flag specifies tags to be added to the bucket in the format of '
683+ '``--tags key value``. You can specify this flag multiple times, '
684+ 'once for each tag.'
685+ ),
686+ }
687+
676688
677689CASE_CONFLICT = {
678690 'name' : 'case-conflict' ,
@@ -1206,7 +1218,16 @@ class MbCommand(S3Command):
12061218 NAME = 'mb'
12071219 DESCRIPTION = "Creates an S3 bucket."
12081220 USAGE = "<S3Uri>"
1209- ARG_TABLE = [{'name' : 'path' , 'positional_arg' : True , 'synopsis' : USAGE }]
1221+ ARG_TABLE = (
1222+ [
1223+ {
1224+ 'name' : 'path' ,
1225+ 'positional_arg' : True ,
1226+ 'synopsis' : USAGE ,
1227+ }
1228+ ]
1229+ + [TAGS ]
1230+ )
12101231
12111232 def _run_main (self , parsed_args , parsed_globals ):
12121233 super (MbCommand , self )._run_main (parsed_args , parsed_globals )
@@ -1222,9 +1243,17 @@ def _run_main(self, parsed_args, parsed_globals):
12221243 "Cannot use mb command with a directory bucket."
12231244 )
12241245
1225- bucket_config = {'LocationConstraint' : self .client .meta .region_name }
12261246 params = {'Bucket' : bucket }
1247+ bucket_config = {}
1248+ bucket_tags = self ._create_bucket_tags (parsed_args )
1249+
1250+ # Only set LocationConstraint when the region name is not us-east-1.
1251+ # Sending LocationConstraint with value us-east-1 results in an error.
12271252 if self .client .meta .region_name != 'us-east-1' :
1253+ bucket_config ['LocationConstraint' ] = self .client .meta .region_name
1254+ if bucket_tags :
1255+ bucket_config ['Tags' ] = bucket_tags
1256+ if bucket_config :
12281257 params ['CreateBucketConfiguration' ] = bucket_config
12291258
12301259 # TODO: Consolidate how we handle return codes and errors
@@ -1239,6 +1268,11 @@ def _run_main(self, parsed_args, parsed_globals):
12391268 )
12401269 return 1
12411270
1271+ def _create_bucket_tags (self , parsed_args ):
1272+ if parsed_args .tags is not None :
1273+ return [{'Key' : tag [0 ], 'Value' : tag [1 ]} for tag in parsed_args .tags ]
1274+ return []
1275+
12421276
12431277class RbCommand (S3Command ):
12441278 NAME = 'rb'
0 commit comments