How to Rename a Bucket in AWS S3

avatar
Borislav Hadzhiev

Last updated: Feb 26, 2024
4 min

banner

# Table of Contents

  1. How to Rename a Bucket in AWS S3
  2. Cost associated with Renaming an S3 Bucket

# How to Rename a Bucket in AWS S3

AWS doesn't offer a single-step functionality to rename an S3 bucket, however, we can manually rename one.

In the following steps, we use the AWS console to create an S3 bucket because the AWS CLI doesn't implement an option to copy a bucket's configuration upon creation.

In order to rename an S3 bucket, you have to:

  1. Navigate to the AWS S3 console and click on the Create Bucket button.
  2. Enter your new bucket's name, select the same region as the old bucket and in the Copy settings from existing bucket section, select your old bucket to copy settings from.

create bucket settings

  1. Scroll down and click on the Create bucket button.
  2. Copy the contents of the old bucket to the new bucket.
  3. Delete the old bucket.

To recursively copy the contents of the old bucket to the new bucket, use the s3 sync command, passing it the source and destination buckets as inputs:

S3 Copy (sync) operations cost about $0.005 per 1,000 requests in the us-east-1 region. For example, if your bucket contains 1,000,000 objects, the Copy operation would cost you 1,000 * $0.005 = $5.
shell
aws s3 sync s3://SOURCE_BUCKET s3://DESTINATION_BUCKET

copy to new bucket

The output of the command shows that the objects of the old bucket were copied to the same paths in the new bucket.

To verify the contents of the old and new buckets are the same, run the s3 ls command on both buckets and verify the total size of the objects is the same.

S3 List operations cost about $0.005 per 1,000 requests, where each request returns a maximum of 1,000 objects (us-east-1 region). For example, if your bucket contains 1,000,000 objects, you would make 1,000 requests and the List operation would cost you $0.005.
shell
# Old bucket aws s3 ls s3://YOUR_OLD_BUCKET --recursive --human-readable --summarize # New bucket aws s3 ls s3://YOUR_NEW_BUCKET --recursive --human-readable --summarize

verify objects copied

The number of objects between the buckets is different in the output of the commands. This is because the command counts the path to a "folder" as an object in the old bucket, and not in the new one. If the Total Size is the same between the buckets, the buckets contain the same objects.

Once you're sure that the objects are successfully copied to the new bucket, the last step is to delete the old bucket.

Before you delete the old bucket, look at its configuration in the AWS S3 console and make sure the configuration between the old and new buckets is in sync.

To delete the old bucket, use the s3 rb command, setting the --force parameter, which deletes all of the bucket's objects.

shell
aws s3 rb s3://YOUR_OLD_BUCKET --force

delete old bucket

You can run the s3 ls command to verify the old bucket has been deleted successfully.

shell
aws s3 ls s3://bucket-old-123

old bucket successfully deleted

# Cost associated with Renaming an S3 Bucket

In short, the associated cost will be insignificant unless you have millions of S3 objects to copy.

The new and old buckets are in the same region, therefore you don't get charged for bandwidth when copying the objects with the s3 sync command.

At the time of writing the Copy requests are priced at about $0.005 per 1,000 requests in the us-east-1 region. One Copy request is performed for each file with the aws sync command.

For example, to sync a bucket that has 1,000,000 objects to another bucket, the 1,000,000 Copy requests would cost 1000 * $0.005 = $5.

Delete requests are free of charge, so deleting the old bucket is not associated with a cost, in fact, it saves on storage.

At the time of writing AWS Free Tier covers 20,000 GET Requests; 2,000 PUT, COPY, POST, or LIST Requests each month.

I've also written an article on how to rename a folder in AWS S3.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.