5
533

How to rename S3 Bucket with AWS CLI

Reading Time: < 1 minute

After creating some time, we may find a better name and want to rename S3 bucket. However there are already objects inside where we do not want to remove it. Thus, let’s discuss how rename.

Methods to rename S3 Bucket

Since there is no direct command, we will make use of other commands to create the same behaviour to rename.

  • Copying Existing Objects
  • Syncing Existing Objects

In the illustration below, let’s assume that you have AWS CLI and python installed. You may refer to the AWS documentation to setup AWS CLI if not installed.

Copying Existing Objects

Instead of moving, we will be copying the objects since it will be safer method if something happen during the operation and we need to re-start the process.

Hence, we will first create the S3 bucket, perform the copy operation, then remove the old bucket once we verify the contents.

aws s3 mb s3://my-bucket-old
aws s3 cp s3://my-bucket-old s3://my-bucket-new --recursive
aws s3 rb s3://my-bucket-old --force

Although copy command does have a few disadvantages over sync on efficiency, it does not impact the renaming concept since the new bucket does not have any existing file.

Syncing Existing Objects

We can also use the sync objects command by replacing the copy step.

aws s3 mb s3://my-bucket-old
aws s3 sync s3://my-bucket-old s3://my-bucket-new
aws s3 rb s3://my-bucket-old --force

Conclusion

Although there are other methods that can replace the concept of renaming, we have to note that these operation have the downside as there will be some time needed on copying or syncing. Thus, we need to consider the external impact when performing this carefully.

Show Comments

No Responses Yet

Leave a Reply