19

I see there is an AWS::S3::S3Object.rename but I can't do it with folders:

AWS::S3::Base.establish_connection!(
 :access_key_id     => APP_CONFIG[:s3_access_key_id],
 :secret_access_key => APP_CONFIG[:s3_secret_access_key]
)
AWS::S3::S3Object.rename(
 "assets/old_name_folder",
 "assets/new_name_folder",
 APP_CONFIG[:s3_bucket]
)

The old_name_folder contains files and folders and I want the renaming to respect this.

I'm obtaining: AWS::S3::NoSuchKey (The specified key does not exist.)

I don't know if I'm doing something wrong or it is just not possible to rename s3 folders.

4 Answers 4

33

The documentation for AWS::S3 explains this pretty well. When storing files on s3, there are no such things as folders. There is a bucket (your APP_CONFIG[:s3_bucket] presumably), and there are objects. That is it. There are no folders. One of your objects might be named /files/public/system/whatever/derp.jpg - but there are no folders there, only an object with a name that looks like a path, and then the value of the object (the actual file residing at that location).

So to answer your question, you cannot rename folders because there is no such thing on s3. You have to rename individual objects.

8
  • pretty well understood so I have to copy all the file paths to the new file paths and remove old file paths.
    – fguillen
    Commented Mar 30, 2011 at 17:29
  • 7
    @fguillen - you don't have to/can't remove the old ones. Just rename the files/objects. The folders you see are just virtual - they are the way the gui tools are interpreting the filenames with /'s in them Commented Mar 30, 2011 at 17:54
  • 16
    thanks for the explanation, i must say though, in my opinion even though under the hood there may not be any folders, it sure as heck looks like folders and it would be nice if they just let you rename the "folder" in the S3 panel and would then rename all the objects that needed it. just sayin
    – FireDragon
    Commented Feb 10, 2013 at 8:22
  • 2
    There are external programs you can use that will let you do this, I've been using 3Hub personally. Commented Feb 11, 2013 at 15:53
  • 10
    I agree that "it is not really a folder" falls short of an explanation. It should be possible to rename these "objects" or "properties" or "virtual folders" or whatever they are. Fact is people want to do it and the ways to do it are cumbersome. Also they may not be folders, but there sure is an option called "create folder".
    – Pablo
    Commented Dec 11, 2019 at 11:09
4

You can copy objects from one s3://[path_1] to another s3://[path_2] via AWS Console. https://docs.aws.amazon.com/cli/latest/reference/s3/mv.html

Example move objects between different buckets:

aws s3 mv s3://[s3-name1]/folder1 s3://[s3-name2]/[folder2] --recursive 

or within the same S3

aws s3 mv s3://[s3-name1]/folder1 s3://[s3-name1]/[folder2] --recursive 
1

The easiest way to rename the folder in S3 bucket is open AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/ or AWS Cloud Shell https://aws.amazon.com/cloudshell/

The benefit with AWS cloud shell is that no need to configure, CloudShell is pre-authenticated with your console credential. (Note-- This service launch yesterday)

aws s3 --recursive mv s3:///<folder_name_from> s3:///<folder_name_to>

See the example below, where I change the name of the folder "firstname" to "first" folder. Also, this command move all the object inside that new folder from the older folder.

enter image description here

0

You cant do this because AWS pricing for every request. So they want to more action. Rename folder or delete will not work. Before you must move / delete etc all files.

Not the answer you're looking for? Browse other questions tagged or ask your own question.