How to rename a file in S3 (and why it's tricky)
TL;DR
Renaming an S3 object requires copying it to a new key and removing the original. S3 Viewer does this server-side on every provider — AWS S3, Cloudflare R2, Backblaze B2, MinIO, and other S3-compatible endpoints — with no size cap: objects above 5 GB copy in multipart parts automatically. It refuses an occupied destination and rejects a source that changed since you reviewed it. Folder rename moves every object under the prefix the same way, and Copy to… and New folder use the same server-side copy.
Steps
Step-by-step.
- 01
In S3 Viewer: open the ⋮ menu and choose Rename
Open the ⋮ menu on the object's row and choose Rename, then type the new key. S3 Viewer issues a server-sideCopyObject, which preserves the object's metadata, then issuesDeleteObjecton the source — only confirming the rename once both succeed. If an object already exists at the new key the rename is refused rather than overwriting it. The file must still match the one you reviewed: an ETag check catches a source that changed underneath you and refuses the rename instead of copying stale bytes. This works the same way on AWS S3, R2, B2, and every other connected provider. - 02
AWS CLI: aws s3 mv
From a terminal,aws s3 mvperforms a server-side copy then a delete. The bytes never leave AWS — there's no data transfer to your machine.aws s3 mv s3://my-bucket/old-key.png s3://my-bucket/new-key.png - 03
AWS SDK: copyObject + deleteObject
If you're scripting it, runcopyObjectfollowed bydeleteObject. Always verify the copy succeeded (HTTP 200 and matching ETag) before deleting the source.MetadataDirectiveandTaggingDirectiveboth default toCOPY, so metadata and tags carry over unless you explicitly ask forREPLACE.const copy = await s3.copyObject({ CopySource: 'my-bucket/old.png', Bucket: 'my-bucket', Key: 'new.png', MetadataDirective: 'COPY', TaggingDirective: 'COPY', }); await s3.deleteObject({ Bucket: 'my-bucket', Key: 'old.png' }); - 04
Files over 5 GB copy in parts, automatically
A singleCopyObjectcall fails above 5 GB, so S3 Viewer switches to a multipart copy automatically —CreateMultipartUpload→UploadPartCopyfor each part →CompleteMultipartUpload— then deletes the source. There is no size cap on rename in S3 Viewer. Scripting it yourself without the app,aws s3 mvdoes the same thing for you. - 05
Verify, then delete
Confirm the new key exists with the right size and ETag before deleting the source. If you skip this and the copy silently fails, you can lose the file — there is no S3 undo. - 06
Update anything that referenced the old key
CDN cache, presigned URLs, database rows, hard-coded asset paths. Renaming an object doesn't propagate — that's on you, regardless of which tool you used.
Under the hood
What's actually happening.
S3 is a flat key-value store. There is no RenameObject API call — keys are immutable once written, by design. Every “rename” in any S3 tool is the same two operations: CopyObject to write the bytes at the new key (server-side, no download), then DeleteObject on the old key.
Two things to handle: a single CopyObject fails above 5 GB, and the pair of calls is not atomic, so a failure between copy and delete can leave you with two keys (or zero, if you deleted first). Metadata and tags carry over on their own — MetadataDirective and TaggingDirective both default to COPY.
S3 Viewer checks that the source is unchanged before copying and deleting it, refuses the rename when something already exists at the target key (you get a conflict error rather than a silent overwrite), and switches to a multipart copy above 5 GB instead of rejecting the file — so there is no practical size limit. This works on AWS S3, R2, B2, and other connected providers, using whichever conditional headers each one enforces and a check immediately beforehand where it doesn't. Copy and delete are still separate calls, not one atomic operation: an external writer can still race them, and if the delete step fails after a successful copy, S3 Viewer says so rather than guessing — it never deletes a destination it just created to undo a partial rename.
FAQ
Common questions.
Can you rename a file in S3?
How do I rename a file in S3 with the AWS CLI?
Does renaming an S3 file cost money?
What happens to metadata and tags when I rename an S3 object?
Can I rename a file in Cloudflare R2?
How do I rename a folder in S3?
Use S3 Viewer for this
Skip the CLI. Try it in the browser.
S3 Viewer turns the steps above into a single click. Open source, self-hostable, free.
Use case
Why teams pick this
Related guides
More how-tos
Create a folder
S3 has no folders — only key prefixes. How the console, the CLI and S3 Viewer create one, and why an empty folder can vanish.
Delete a file
Versioning, delete markers, MFA Delete — and how to actually purge instead of soft-deleting.
Upload large files
How large uploads work in S3 Viewer and from the CLI — streaming, retries, and the 5 GB single-PUT cap.