AWS

How to rename a bucket in S3?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

A S3 bucket name is immutable. That means it's not possible to change it, without removing and creating a new bucket.

This is why the process for renaming a bucket is as follows:

  • Create a new bucket with the desired name
  • Move the data from the old bucket to it
  • Delete the old bucket

With the AWS CLI that would be:

# Create new bucket
aws s3 mb s3://[NEW_BUCKET_NAME]
# Sync the content from the old bucket to the new bucket
$ aws s3 sync s3://[OLD_BUCKET_NAME] s3://[NEW_BUCKET_NAME]
# Remove old bucket
$ aws s3 rb --force s3://[OLD_BUCKET_NAME]