Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cost of renaming a folder in AWS S3 bucket

I want to rename a folder in S3 bucket, I understand that rename will run a PUT request which costs 1 cent per 1000 request.

However, the PUT request is defined as a COPY and involves with also a GET

My question is, when we rename a folder in S3 bucket, does it involve copying all sub-folders and files to a new folder with the name I want (which costs more than 1 PUT request), or it just simply 1 PUT request to change the name without touching all the items within the folder.

like image 376
Casper Avatar asked Oct 07 '15 19:10

Casper


People also ask

Can I rename a folder in AWS S3?

All you have to do is to select a file or folder you want to rename and click on the “Rename” button on the toolbar. You can use the F2 keyboard standard hotkey tool. Now, type the new name and click ok. The file or folder will be renamed – as simple as that.

Is it possible to rename an S3 bucket?

An Amazon S3 bucket is owned by the AWS account that created it. Bucket ownership is not transferable to another account. When you create a bucket, you choose its name and the AWS Region to create it in. After you create a bucket, you can't change its name or Region.

How do I rename a file in S3 bucket?

There is no direct method to rename a file or folder in Amazon S3. But we can perform a little bit edge around. What you have to do is to create a new “folder” in S3 and then move all of the files from that “folder” to the new “folder.” Once all files are moved, we can remove the source “folder.”

Can S3 buckets have folders?

You can have folders within folders, but not buckets within buckets. You can upload and copy objects directly into a folder.


1 Answers

In case you've missed it... there are no folders in S3.

The object /pics/funny/cat.jpg is not a file called cat.jpg inside a folder called funny inside another folder called pics.

In fact, it is a file with an 18-character name: pics/funny/cat.jpg. The hierarchy shown in the console is largely for human convenience, and the ability to create new folders in the console is an illusion, also.

So, yes, renaming a "folder" actually means making a new copy of each object in the "folder," with a change to the object names to look like their are in the path.

This can be done with a PUT/COPY request ($0.005 per 1000 depending on the region) followed by a DELETE request of the old object (free). There is no corresponding GET request, because PUT/COPY is an atomic operation inside S3, so actually downloading and re-uploading the data is avoided.

like image 142
Michael - sqlbot Avatar answered Sep 19 '22 18:09

Michael - sqlbot