Skip to Content

6 Tips For Renaming An AWS S3 Folder

Sharing is caring!

We strive to provide you with authoritative, trustworthy, and expert advice. In doing so, the staff at clouddropout.com performs extensive research, editing, and fact checking to every post on this webiste. If you feel that this article can improve, please feel free to reach us at staff@clouddropout.com

Before continuing this article, I wanted to let you know that I have a Youtube Channel where I showcase all sorts of video content related to Tech. Subscribing would mean a lot to me, and I very much appreicate all the support!

Users are able to rename AWS S3 bucket folders and files using the AWS S3 CLI command line.

It is possible to ‘rename’ bucket folders or files using the console interface, but not recommended especially if users are trying to manipulate thousands of objects at once.

Before implementing the command to rename the folders and files, users should also consider why they are needing to do so, what impact it will have on the rest of their applications, and whether there are any dependencies associated with the old folder and file names.

Lastly, users should also consider the cost of doing such changes.

Moving millions of objects in an S3 bucket, and renaming everything can start to add up in price!


S3 rename folder CLI

There is no explicit way to rename folder or file names in amazon S3.

Instead, users have the ability to implement the mv command in the command line interface, which moves the file objects to another location. 

Also important to consider, amazon s3 is not constructed hierarchically through folders.

Instead, each object has its own unique identifier in the form of prefixes that users can use to perform operations on the objects. 

Let’s look at an example of renaming a ‘folder’ prefix in amazon s3 using the CLI.

General command structure:

<LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri>

Commands used in conjunction with above cli structure:

  • Mv
  • —Recursive

For this scenario, let’s just consider ‘renaming’ s3 bucket ‘folders’ and files by moving them to a specified bucket key.

The following mv command moves a single s3 object to a specified bucket and key [1]:

aws s3 mv s3://mybucket/move.txt s3://mybucket/move2.txt

Output:

move: s3://mybucket/move.txt to s3://mybucket/move2.txt

As you can see, a single mv operation through the amazon s3 cli can basically move a specified source object in an s3 bucket to a different name. This effectively ‘renames’ your file in s3.

A more advanced option in conjunction with the mv command would be using the —recursive operation. 

When applied alongside the mv command, the —recursive operation is performed on all files or objects under the specified directory or prefix [1].

Let’s take a look at how that works in practice.

aws s3 –recursive mv s3://<bucketname>/<folder_name_from> s3://<bucket>/<folder_name_to>

What happens in this case, the recursive operation just copies all the objects specified in the <folder_name_from> and moves them to the other folder/directory labeled as <folder_name_to>.

That is how you can rename an amazon s3 bucket folder using the cli.


S3 Rename Folder Alternative Commands

If you want to ensure that the copying of your amazon s3 object files has been made appropriately before deleting anything, you can actually use the cp and rm commands instead of just using the mv command (which copies and removes everything in one sweep).

Here’s what that looks like:

aws s3 cp s3://source_folder/ s3://destination_folder/ –recursive

aws s3 rm s3://source_folder –recursive

This can be a great way to ensure you are holding your data and that nothing is deleted until absolutely necessary!


S3 rename folder disabled

If you feel that you are unable to rename a folder or file in amazon s3, consider the approach you are taking. Check to see if you’re using the console, command line interface, or AWS SDK. 

Furthermore, you want to check your IAM permissions and if the account being used to perform these operations is actually allowed to rename your object files.

When taking a quick look at your IAM permissions, make sure you have the following under actions:

“s3:GetObjectVersion”,

 “s3:DeleteObjectVersion”,

 “s3:PutObjectAcl”,

 “s3:GetObjectAcl”

This will let your account have the correct permissions to be able to rename your bucket folders and files.


s3 rename folder console

Directly renaming your s3 folder is not possible. Instead you will want to copy the existing objects that are labeled with a certain name, and move them to the new ‘renamed’ location. 

You can accomplish this in the console, by doing the following:

Select the file then select Actions > Rename in the GUI.

To rename a folder, you instead have to create a new folder, and select the contents of the old one and copy/paste it across (Under “Actions” again) [2].

Take note that moving objects to a newly renamed object in s3 through the console is only efficient when doing small changes. 

For larger workloads that constitute perhaps thousands of objects, you will want to consider using the cli command to accomplish your task!


s3 rename folder cost

With everything AWS, you are charged only for what you use. AWS has a pay as you go pricing model that can make it very cost efficient by literally only paying for exactly what you need and are doing inside the platform.

If you’re wondering about the cost of renaming your s3 folder and files, consider the amazon s3 pricing specifications.

Essentially you are charged per request.

Taking an example of renaming 200,000 objects in amazon s3, you have to perform the following requests:

  • 200 LIST requests (single LIST request returns max 1000 items)
  • 200 000 GET requests
  • 200 000 COPY requests
  • 200 000 HEAD requests
  • 200 000 PUT requests

Combine these requests with what is found in the s3 pricing page [3], and you can come up with the approximate cost of $4.


S3 rename bucket name

If you not only need to rename your bucket objects, but the bucket itself, you will need to create a new bucket, copy and move all contents from the old bucket to the new one, then delete the old bucket. This is similar in scope to renaming bucket objects, with the extra step of creating a new entire bucket and deleting the old one.

Here’s the command to rename your s3 bucket name:

aws s3 mb s3://[new-bucket]

aws s3 sync s3://[old-bucket] s3://[new-bucket]

aws s3 rb –force s3://[old-bucket]


Source Content:

[1] https://docs.aws.amazon.com/cli/latest/reference/s3/mv.html

[2]https://stackoverflow.com/questions/21184720/how-to-rename-files-and-folder-in-amazon-s3

[3] https://aws.amazon.com/s3/pricing/