How to Copy and Rename Files in S3 with AWS Emulator
In S3, you rename a file (object) or move it to another folder or prefix by copying it and then deleting the original. S3 has no dedicated rename operation for general purpose buckets. I ran the method of running aws s3api copy-object and then delete-object, and aws s3 mv, which does both in one command, with AWS Emulator, without using an AWS account. I also include the commands and their output for preventing overwrites and for passing file names that contain Japanese characters or spaces.
The test environment was Ubuntu 24.04 (x86_64), AWS Emulator 1.0.624 (released November 26, 2026), and AWS CLI 2.42.4. I did not use an AWS account or credentials. I did not test behavior on real S3, pricing, copying files larger than 5 GB, renaming in a bucket with versioning enabled, or S3 Express One Zone directory buckets. Where I describe real S3, I rely on the official documentation. According to the AWS Emulator official documentation, AWS checks the emulator's behavior against the real service only in the US West (Oregon, us-west-2) Region (global services use us-east-1). The us-east-1 S3 I used in this article is outside that scope.
- 1. In S3, renaming means copying and then deleting the original
- 2. Start the emulator and put a file
- 3. Rename with copy-object and delete-object
- 4. An existing file at the destination is overwritten silently
- 5. Rename in one step with aws s3 mv
- 6. Rename a whole folder
- 7. Move to another bucket
- 8. File names with Japanese characters or spaces
- 9. When the source key is wrong
In S3, renaming means copying and then deleting the original
The S3 User Guide page on copying, moving, and renaming objects explains that renaming an object means copying it and then deleting the original. Moving an object to another bucket works the same way: it is copied to the destination and the original is deleted. According to the same page, the renamed copy gets a new last-modified time.
A single CopyObject request can copy up to 5 GB. According to the CopyObject API reference, larger files are copied with UploadPartCopy in a multipart upload.
There is also a RenameObject API, but according to the RenameObject API reference, it only works on objects in S3 Express One Zone directory buckets. When I ran it against a general purpose bucket in the emulator, it was rejected with NotImplemented.
$ aws s3api rename-object --bucket example-bucket --key reports/november.csv --rename-source reports/2026-11.csv
aws: [ERROR]: An error occurred (NotImplemented) when calling the RenameObject operation: A header you provided implies functionality that is not implemented
Start the emulator and put a file
AWS Emulator is an emulator that accepts AWS API calls locally. According to the official documentation, it does not require an AWS account, and requests are not sent to AWS. The installation steps and the environment variables that point the AWS CLI at the emulator are covered in a separate article, "How to Install AWS Emulator on Ubuntu and Get Started." In this article, I used the environment variables from the official documentation in a shell, and sent commands to the emulator started with aws-emulator -t off. -t off turns off telemetry, which is usage data the emulator sends to AWS by default.
If the connection works, the user name in the ARN returned by aws sts get-caller-identity is emulator. (The 12-digit account ID is replaced.) I created two buckets and put one CSV file in one of them. To see what a copy carries over, I set Content-Type, metadata, and tags on the file.
$ aws sts get-caller-identity --query Arn --output text
arn:aws:iam::<12桁のアカウントID>:user/emulator
$ aws s3 mb s3://example-bucket
make_bucket: example-bucket
$ aws s3 mb s3://example-archive
make_bucket: example-archive
$ printf "month,total\n2026-11,42\n" > report.csv; cat report.csv
month,total
2026-11,42
$ aws s3api put-object --bucket example-bucket --key reports/2026-11.csv --body report.csv --content-type text/csv --metadata owner=tama --tagging "status=final" --query ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3api head-object --bucket example-bucket --key reports/2026-11.csv --query "{LastModified:LastModified,ETag:ETag,ContentType:ContentType,Metadata:Metadata}"
{
"LastModified": "2026-11-26T05:44:03+00:00",
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ContentType": "text/csv",
"Metadata": {
"owner": "tama"
}
}
Rename with copy-object and delete-object
I renamed reports/2026-11.csv to reports/november.csv. First I used copy-object to copy it to a key with the new name. For --copy-source, pass "bucket name/key". --if-none-match "*" stops the copy if a file with the same name already exists at the destination. I test this in the next section.
$ aws s3api copy-object --bucket example-bucket --key reports/november.csv --copy-source example-bucket/reports/2026-11.csv --if-none-match "*"
{
"ServerSideEncryption": "AES256",
"CopyObjectResult": {
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"LastModified": "2026-11-26T05:44:07+00:00",
"ChecksumType": "FULL_OBJECT",
"ChecksumCRC64NVME": "stXcN9mYgUI="
}
}
The copy has the same ETag because its contents are identical. LastModified changed to the copy time (from 05:44:03 to 05:44:07). Content-Type, metadata, and tags were carried over even though I did not specify them.
$ aws s3api head-object --bucket example-bucket --key reports/november.csv --query "{LastModified:LastModified,ETag:ETag,ContentType:ContentType,Metadata:Metadata}"
{
"LastModified": "2026-11-26T05:44:07+00:00",
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ContentType": "text/csv",
"Metadata": {
"owner": "tama"
}
}
$ aws s3api get-object-tagging --bucket example-bucket --key reports/november.csv --output text
TAGSET status final
According to the CopyObject API reference, the x-amz-metadata-directive and x-amz-tagging-directive headers, which control how metadata and tags are handled, default to COPY (carry over from the source) when not specified. For changing metadata during a copy and the caveats involved, see the separate article "How to Add Tags and Metadata to Files in S3 with AWS Emulator."
After the copy succeeds, delete the original with delete-object. Only the new name remains in the listing.
$ aws s3api delete-object --bucket example-bucket --key reports/2026-11.csv
$ aws s3 ls s3://example-bucket --recursive
2026-11-26 05:44:07 23 reports/november.csv
The copy and the delete are separate requests. In a script, check the exit code of copy-object and run delete-object only if it succeeded, so that a failed copy does not lead to deleting the original.
An existing file at the destination is overwritten silently
If a file already exists at the destination key, copy-object does not return an error and overwrites it. I put a December CSV at reports/december.csv and then copied the November file over it.
First, with --if-none-match "*", the request was rejected with PreconditionFailed, and the December contents were left as they were.
$ printf "month,total\n2026-12,7\n" > dec.csv; aws s3api put-object --bucket example-bucket --key reports/december.csv --body dec.csv --query ETag
"\"cc00c2de2422a720375b82e658adeece\""
$ aws s3api copy-object --bucket example-bucket --key reports/december.csv --copy-source example-bucket/reports/november.csv --if-none-match "*"
aws: [ERROR]: An error occurred (PreconditionFailed) when calling the CopyObject operation: At least one of the pre-conditions you specified did not hold
$ aws s3 cp s3://example-bucket/reports/december.csv -
month,total
2026-12,7
The CopyObject API reference also states that when If-None-Match is set to * and the destination key already exists, the request returns 412 Precondition Failed.
Without --if-none-match, the copy succeeded, and the December contents were replaced by the November contents.
$ aws s3api copy-object --bucket example-bucket --key reports/december.csv --copy-source example-bucket/reports/november.csv --query CopyObjectResult.ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3 cp s3://example-bucket/reports/december.csv -
month,total
2026-11,42
If a file might already exist at the destination of a rename, add --if-none-match "*" to the copy. The S3 User Guide page on copying, moving, and renaming notes that when you copy or move objects in the console, it warns you to enable versioning on buckets where it is disabled, to guard against unintended overwrites and deletions.
Rename in one step with aws s3 mv
aws s3 mv performs the copy and the delete in one command. According to the mv reference, mv copies the object to the destination and then deletes the original. --no-progress turns off the transfer progress display.
$ aws s3 mv s3://example-bucket/reports/november.csv s3://example-bucket/reports/2026-11-final.csv --no-progress
move: s3://example-bucket/reports/november.csv to s3://example-bucket/reports/2026-11-final.csv
$ aws s3 ls s3://example-bucket --recursive
2026-11-26 05:44:16 23 reports/2026-11-final.csv
2026-11-26 05:44:13 23 reports/december.csv
Content-Type, metadata, and tags were also carried over with aws s3 mv.
$ aws s3api head-object --bucket example-bucket --key reports/2026-11-final.csv --query "{LastModified:LastModified,ETag:ETag,ContentType:ContentType,Metadata:Metadata}"
{
"LastModified": "2026-11-26T05:44:16+00:00",
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ContentType": "text/csv",
"Metadata": {
"owner": "tama"
}
}
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11-final.csv --output text
TAGSET status final
According to the same reference, you can choose what is carried over with --copy-props. The default, default, carries over tags and metadata. There is also --no-overwrite, which does not overwrite a file that already exists at the destination.
Rename a whole folder
According to the page on organizing objects using folders, S3 general purpose buckets have no hierarchy, and folders are represented by a common prefix at the start of the key. The same page also states that you cannot rename a folder in the console.
To change drafts/ to published/, use aws s3 mv with --recursive to move every object that starts with drafts/. First I put three copies of report.csv under drafts/. With --dryrun, the command only displays what would be moved and does not move anything.
$ for m in 01 02 03; do aws s3 cp report.csv s3://example-bucket/drafts/2026-$m.csv --only-show-errors; done; aws s3 ls s3://example-bucket/drafts/
2026-11-26 05:44:19 23 2026-01.csv
2026-11-26 05:44:20 23 2026-02.csv
2026-11-26 05:44:21 23 2026-03.csv
$ aws s3 mv s3://example-bucket/drafts/ s3://example-bucket/published/ --recursive --dryrun
(dryrun) move: s3://example-bucket/drafts/2026-01.csv to s3://example-bucket/published/2026-01.csv
(dryrun) move: s3://example-bucket/drafts/2026-02.csv to s3://example-bucket/published/2026-02.csv
(dryrun) move: s3://example-bucket/drafts/2026-03.csv to s3://example-bucket/published/2026-03.csv
After --dryrun, the three files under drafts/ were still there.
$ aws s3 ls s3://example-bucket/drafts/
2026-11-26 05:44:19 23 2026-01.csv
2026-11-26 05:44:20 23 2026-02.csv
2026-11-26 05:44:21 23 2026-03.csv
When I ran it without --dryrun, all three moved to published/. The order of the output was not the file name order.
$ aws s3 mv s3://example-bucket/drafts/ s3://example-bucket/published/ --recursive --no-progress
move: s3://example-bucket/drafts/2026-01.csv to s3://example-bucket/published/2026-01.csv
move: s3://example-bucket/drafts/2026-03.csv to s3://example-bucket/published/2026-03.csv
move: s3://example-bucket/drafts/2026-02.csv to s3://example-bucket/published/2026-02.csv
$ aws s3 ls s3://example-bucket --recursive
2026-11-26 05:44:24 23 published/2026-01.csv
2026-11-26 05:44:24 23 published/2026-02.csv
2026-11-26 05:44:24 23 published/2026-03.csv
2026-11-26 05:44:16 23 reports/2026-11-final.csv
2026-11-26 05:44:13 23 reports/december.csv
Move to another bucket
Moving to a different bucket uses the same syntax. I moved reports/december.csv in example-bucket to 2026/december.csv in example-archive.
$ aws s3 mv s3://example-bucket/reports/december.csv s3://example-archive/2026/december.csv --no-progress
move: s3://example-bucket/reports/december.csv to s3://example-archive/2026/december.csv
$ aws s3 ls s3://example-archive --recursive
2026-11-26 05:44:25 23 2026/december.csv
$ aws s3 ls s3://example-bucket/reports/
2026-11-26 05:44:16 23 2026-11-final.csv
According to the copying, moving, and renaming page, copying or moving across Regions on real S3 incurs data transfer charges.
File names with Japanese characters or spaces
When you copy a key that contains Japanese characters or spaces, such as reports/11月 報告.csv, pay attention to how you write --copy-source. The CopyObject API reference says the value of x-amz-copy-source should be URL-encoded. However, when I passed a URL-encoded value to the AWS CLI, it was rejected with NoSuchKey.
$ aws s3 cp report.csv "s3://example-bucket/reports/11月 報告.csv" --only-show-errors; aws s3 ls s3://example-bucket/reports/
2026-11-26 05:44:28 23 11月 報告.csv
2026-11-26 05:44:16 23 2026-11-final.csv
$ aws s3api copy-object --bucket example-bucket --key reports/monthly-11.csv --copy-source "example-bucket/reports/11%E6%9C%88%20%E5%A0%B1%E5%91%8A.csv" --query CopyObjectResult.ETag
aws: [ERROR]: An error occurred (NoSuchKey) when calling the CopyObject operation: The specified key does not exist.
When I passed the Japanese characters and spaces as they are, the copy succeeded. Looking at the headers sent with --debug, the AWS CLI URL-encoded the value itself.
$ aws s3api copy-object --bucket example-bucket --key reports/monthly-11.csv --copy-source "example-bucket/reports/11月 報告.csv" --query CopyObjectResult.ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3api copy-object --bucket example-bucket --key reports/monthly-11b.csv --copy-source "example-bucket/reports/11月 報告.csv" --debug 2>&1 | grep "^x-amz-copy-source:"
x-amz-copy-source:example-bucket/reports/11%E6%9C%88%20%E5%A0%B1%E5%91%8A.csv
aws s3 mv also worked with a name containing Japanese characters and spaces, as long as I wrapped the path in quotes and passed it as is.
$ aws s3 mv "s3://example-bucket/reports/11月 報告.csv" "s3://example-bucket/reports/11月 月報.csv" --no-progress
move: s3://example-bucket/reports/11月 報告.csv to s3://example-bucket/reports/11月 月報.csv
$ aws s3 ls s3://example-bucket/reports/
2026-11-26 05:44:31 23 11月 月報.csv
2026-11-26 05:44:16 23 2026-11-final.csv
2026-11-26 05:44:30 23 monthly-11.csv
2026-11-26 05:44:30 23 monthly-11b.csv
When the source key is wrong
When the source key does not exist, copy-object stopped with NoSuchKey, and aws s3 mv stopped with a 404 from HeadObject. The exit codes were 254 for copy-object and 1 for aws s3 mv.
$ aws s3api copy-object --bucket example-bucket --key reports/x.csv --copy-source example-bucket/reports/nothing.csv
aws: [ERROR]: An error occurred (NoSuchKey) when calling the CopyObject operation: The specified key does not exist.
$ aws s3 mv s3://example-bucket/reports/nothing.csv s3://example-bucket/reports/x.csv
fatal error: An error occurred (404) when calling the HeadObject operation: Key "reports/nothing.csv" does not exist
If you get NoSuchKey with a key that contains Japanese characters, check whether you URL-encoded --copy-source yourself.





