Trip
Trip

Reputation: 27114

How do you rename a folder in a bucket on S3?

As simple as it sounds, it seems like an extraordinarily complicated task.

Upvotes: 12

Views: 9450

Answers (5)

m360ai
m360ai

Reputation: 1

Go into the S3 console and use the following:

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

Upvotes: 0

Brendan
Brendan

Reputation: 938

If you use the S3 Management Console, you can cut and paste. Go into the folder you want, click Ctrl + A, then click Actions > Cut. Make your new folder and click Actions > Paste.

Upvotes: 2

Dan Tenenbaum
Dan Tenenbaum

Reputation: 1889

Seems like the AWS Command Line Interface is the new way to do stuff like this. Using it, you can rename a folder like this:

aws s3 mv --recursive s3://bucketname/oldfoldername s3://bucketname/newfoldername

Be sure and start with the --dryrun option to make sure it will do what you think it's going to do.

Upvotes: 12

Ronen Botzer
Ronen Botzer

Reputation: 7117

If you're using the aws-s3 gem, the following code will rename folder OLD_FOLDER_NAME in bucket BUCKET_NAME to NEW_FOLDER_NAME:

bsize = OLD_FOLDER_NAME.size
bucket = AWS::S3::Bucket.find(BUCKET_NAME)
bucket.objects({:prefix=>OLD_FOLDER_NAME}).each do |o|
  AWS::S3::S3Object.rename(o.key, NEW_FOLDER_NAME + o.key[bsize..-1], BUCKET_NAME)
end

That's it. Folders aren't real objects, so all you have to do is rename all the objects that end up in that specific path to the new path. The virtual folder will be renamed as a result.

Upvotes: 12

Trip
Trip

Reputation: 27114

Use BucketExplorer! This is a great app! You can do pretty much anything you ever wanted to do to your s3 in a very very easy to understand GUI

Upvotes: 0

Related Questions