Wed Sep 22 2021·3 min read
Photo by Sébastien Beauchamp
To rename a folder in an S3 bucket, you have to:
Objectstab, optionally use the search input to find your folder
Actionsbutton and select
Destinationinput field, enter the complete S3 URI pointing to the folder, e.g.
s3://YOUR_BUCKET/YOUR_FOLDER/and click on 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
The action applies to all of the objects in the specified folder.
To rename an S3 folder with the AWS CLI, run the
s3 mv command, passing in
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
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 -
By setting the
--dryrun parameter we instruct the AWS CLI to print the
commands output, without actually running it.
aws s3 mv s3://YOUR_BUCKET/YOUR_FOLDER/ s3://YOUR_BUCKET/NEW_FOLDER/ --recursive --dryrun
To verify the S3 Folder has been renamed, you can run the s3 ls command.
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
0 Bytes. That object is the s3 path - the "folder" itself.
If you want to delete the empty folder, run the
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, you can run the
s3 rm command in real
mode by removing the
I'll send you 1 email a week with links to all of the articles I've written that week