How to Rename a Bucket in AWS S3

avatar

Borislav Hadzhiev

Wed Sep 22 20213 min read

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 does not 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 does not 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 in 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 in the us-east-1 region. For example, if your bucket contains 1,000,000 objects, the List operation would cost you 1,000 * $0.005 = $5
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

In the output of the commands above the number of objects between the buckets is different. 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

To verify the old bucket has been deleted successfully, you can run the s3 ls command:

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.

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee