Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename "PREFIX" in Amazon s3 via aws cli?

I understand that in Amazon s3, there are only buckets and objects. There are no such things as folders and all files sit in the same bucket, and that objects that appear to be in a folder only have a prefix in front of their file name.

Now my question is... is there a way to change the PREFIX using AWS CLI?

like image 655
ayjay Avatar asked May 02 '14 22:05

ayjay


People also ask

What is S3 prefix name?

PDFRSS. You can use prefixes to organize the data that you store in Amazon S3 buckets. A prefix is a string of characters at the beginning of the object key name. A prefix can be any length, subject to the maximum length of the object key name (1,024 bytes).

How do I rename an AWS file on my S3?

There is no direct method to rename the file in s3. what do you have to do is copy the existing file with new name (Just set the target key) and delete the old one.

Can we rename an object in S3?

You can use aws s3 mv command to rename or move files (objects) or folders (keys) in an S3 bucket.

Can we rename folder in S3 bucket?

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.


1 Answers

In awscli2 I was able to accomplish this with the following command:

aws s3 mv --recursive s3://bucket/prefix1/ s3://bucket/prefix2/

I ran a quick test (dryrun) prior to doing this by checking the output of:

aws s3 --dryrun mv --recursive s3://bucket/prefix1/ s3://bucket/prefix2/
like image 160
Will Gleich Avatar answered Oct 23 '22 23:10

Will Gleich