Create an S3 bucket in a specific AWS region using CLI Command


S3 buckets are default created in the region that is set in the AWS configure profile, if you want to create an S3 bucket in a specific region you can make use of the option --region followed by the region name.



Example: Create a bucket in us-east-1 region
% aws s3 mb s3:\\my-unique-bucket-name --region us-west-1


Example: Create a bucket in eu-west-1 region
% aws s3 mb s3:\\my-unique-bucket-name --region eu-west-1


As you can see in the below example, I have the default region set to us-west-1, when I create a new s3 bucket in us-east-1 region, I can do an ls with --region us-east-1 to see all the buckets in that specific region

% aws configure get region
us-west-1

% aws s3 mb s3:\\c2c-bucket-1 --region us-east-1
make_bucket: c2c-bucket-1

% aws s3 ls --region us-east-1
2022-08-16 23:48:37 c2c-bucket-1


Create S3 bucket in specific region

If you do not have permission to create buckets in a specific region you will get AccessDenied on CreateBucket and ListBuckets operations.

% aws s3 mb s3://c2c-bucket-2 --region us-east-2
make_bucket failed: s3://c2c-bucket-2 An error occurred (AccessDenied) when 
calling the CreateBucket operation: Access Denied
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.