-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
What is the issue?
The script doesn't run. It throws an error.
Also, it looks like source and destination are swapped.
How can someone reproduce this issue (if applicable)?
go mod init example
Download the file
Create buckets my_src_bucket
and my_dest_bucket
(rename because namespace is global)
Create object s3://my_src_bucket/path/to/object.txt
`go run main.go -s my_src_bucket -d my_dest_bucket -o path/to/object.txt
What is the actual result when the preceding steps are followed (if applicable)?
Got an error copying item:
operation error S3: CopyObject, https response error StatusCode: 400, RequestID: TNVFWGV3Y6TNXY7E, HostID: iUjX+qz2SzFsl1yF5LdmcroL6OhNUTFzS4Br6QRQQkJI3ZxykhSfYh1ulTpyIvvGukwg1AW152E=, api error InvalidArgument: Invalid copy source object key
(Same result if source and dest bucket names are swapped)
What was the result you expected instead (if applicable)?
No error thrown.
Object s3://my_dest_bucket/path/to/object.txt now exists
Environment details to help us try to reproduce the issue (if applicable)
- Operating system and version: Amazon Linux 2
- SDK or tool name: AWS SDK for go
- SDK or tool version: v2
Any other related details we should know about?
This line looks wrong.
CopySource: destinationBucket,
That's the wrong way around, isn't it?
Also, that's the wrong format.
the docs say
For objects not accessed through an access point, specify the name of the source
bucket and the key of the source object, separated by a slash (/). For example,
to copy the object reports/january.pdf from the bucket awsexamplebucket, use
awsexamplebucket/reports/january.pdf. The value must be URL encoded.
So shouldn't this be
input := &s3.CopyObjectInput{
Bucket: aws.String(url.PathEscape(*destinationBucket)),
CopySource: aws.String(*sourceBucket + "/" + *objectName),
Key: objectName,
}
I also don't know if the source should be URL escaped
The unit test should have a GetObject call after the copy.