How to rename a file in S3 (and why it's tricky)
Amazon S3 has no rename API — keys are immutable, by design. Cloudflare R2 follows the same S3 API and inherits the same constraint. To rename, you copy the object to the new key and delete the original. The AWS CLI does it with `aws s3 mv`; the SDKs do it with copyObject + deleteObject; S3 Viewer wraps the same pattern in a single right-click and preserves metadata and tags by default.
Step-by-step.
- 01
In S3 Viewer: right-click → Rename
Right-click any object in the file browser, choose Rename, type the new key. S3 Viewer issues a server-sideCopyObjectwithMetadataDirective: 'COPY'andTaggingDirective: 'COPY', verifies the destination, then issuesDeleteObjecton the source — only confirming the rename when both succeed. - 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. PassMetadataDirective: 'COPY'andTaggingDirective: 'COPY'or you silently lose metadata and tags — the SDK defaults replace them.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 need multipart copy
A singleCopyObjectcall fails above 5 GB. Switch to multipart copy:CreateMultipartUpload→UploadPartCopyfor each part →CompleteMultipartUpload. S3 Viewer makes this switch automatically the moment the source object crosses 5 GB — you don't think about it. - 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.
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.
Three things to handle: copies over 5 GB need multipart copy; metadata and tags are dropped unless you pass MetadataDirective: 'COPY' and TaggingDirective: 'COPY'; and the operation is not atomic, so a failure between copy and delete can leave you with two keys (or zero, if you deleted first).
S3 Viewer handles all three: it issues a multipart copy above the threshold, sets MetadataDirective and TaggingDirective to COPY by default, and only deletes the source after the destination write returns success. The same pattern works against Cloudflare R2 and any other S3-compatible provider.
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?
Skip the CLI. Try it in the browser.
S3 Viewer turns the steps above into a single click. Open source, self-hostable, free for personal use.
Why teams pick this
More how-tos
Delete a file
Versioning, delete markers, MFA Delete — and how to actually purge instead of soft-deleting.
Upload large files
Multipart upload — part sizes, parallelism, retries, and the 5 GB single-PUT cap that pushes you to multipart.
Download a file
Browser, AWS CLI, or presigned URL — three ways, with auto-inferred filenames and zero key exposure.