Last updated: Feb 26, 2024
Reading time·3 min

To rename a folder in an S3 bucket, you have to:
Objects tab, optionally use the search input to find your folder.Actions button and select Move.
Destination input field, enter the complete S3 URI pointing to the
folder, e.g. s3://YOUR_BUCKET/YOUR_FOLDER/ and click on the Move button.
The Move action creates a copy of the objects with an updated path and a new
last-modified date.
The original objects contained in the folder are then deleted.
The action applies to all the objects in the specified folder.
To rename an S3 folder with the AWS CLI, run the s3 mv command, passing it
the complete S3 URI of the current folder's location and the S3 URI of the
desired folder's location.
To make the command apply to nested paths, set the --recursive parameter.
aws s3 mv s3://YOUR_BUCKET/YOUR_FOLDER/ s3://YOUR_BUCKET/NEW_FOLDER/ --recursive

We use the s3 mv command to move the contents of a directory recursively to a new directory, in other words to rename the directory.
The output from the command shows that the files stored in the bucket's
my-folder-1 directory were moved to the destination directory of
your-folder-1.
By setting the --dryrun parameter we instruct the AWS CLI to print the
command's output without actually running it.
aws s3 mv s3://YOUR_BUCKET/YOUR_FOLDER/ s3://YOUR_BUCKET/NEW_FOLDER/ --recursive --dryrun

You can run the s3 ls command to verify the S3 Folder has been renamed.
aws s3 ls s3://YOUR_BUCKET/NEW_FOLDER/ --recursive --human-readable --summarize

You can also use the s3 ls command to verify that the old folder does not
contain any objects.
aws s3 ls s3://YOUR_BUCKET/OLD_FOLDER/ --recursive --human-readable --summarize

The output from the s3 ls command shows that the old folder contains 1 object
of 0 Bytes. That object is the S3 path - the "folder" itself.
If you want to delete the empty folder, run the s3 rm command.
Let's first run it in test mode with the --dryrun parameter because it's a
destructive operation.
aws s3 rm s3://YOUR_BUCKET/OLD_FOLDER/ --dryrun

If the output matches your expectations, run the s3 rm command in real mode by
removing the --dryrun parameter.
I've also written an article on how to rename a Bucket in AWS S3.
You can learn more about the related topics by checking out the following tutorials: