I've got several objects stored in Amazon S3 whose content-type I need to change from text/html
to application/rss+xml
. I gather that it should be possible to do this with a copy command, specifying the same path for the source and destination. I'm trying to do this using the AWS cli tools, but I'm getting this error:
$ aws s3 cp s3://mybucket/feed/ogg/index.html \
s3://mybucket/feed/ogg/index.html \
--content-type 'application/rss+xml'
copy failed: s3://mybucket/feed/ogg/index.html
to s3://mybucket/feed/ogg/index.html
A client error (InvalidRequest) occurred when calling the
CopyObject operation: This copy request is illegal because it is
trying to copy an object to itself without changing the object's
metadata, storage class, website redirect location or encryption
attributes.
If I specify a different path for source and destination, I don't get the error:
$ aws s3 cp s3://mybucket/feed/ogg/index.html \
s3://mybucket/feed/ogg/index2.html \
--content-type 'application/rss+xml'
copy: s3://mybucket/feed/ogg/index.html
to s3://mybucket/feed/ogg/index2.html
Even though the command completes successfully, the index2.html
object is created with the text/html
content type, not the application/rss+xml
type that I specified.
How can I modify this command-line to make it work?
To switch between different AWS accounts, set the AWS_profile environment variable at the command line via export AWS_PROFILE=profile_name . Setting the env variable changes the default profile until the end of your shell session or until you set the variable to a different value.
You can use the Amazon S3 console to edit metadata of existing S3 objects.
Use the s3 cp command to copy objects from a bucket or a local directory.
It's possible to use the low level s3api
to make this change:
$ aws s3api copy-object --bucket archive --content-type "application/rss+xml" \
--copy-source archive/test/test.html --key test/test.html \
--metadata-directive "REPLACE"
http://docs.aws.amazon.com/cli/latest/reference/s3api/copy-object.html
The problem was just not being able to specify the --metadata-directive
. Thanks for pointing out the open issue / feature request, nelstrom!
You can also do it with the higher level API, by copying a file over itself but marking it as a change in metadata:
aws s3 cp \
--content-type "application/rss+xml" \
--metadata-directive REPLACE \
s3://mybucket/myfile \
s3://mybucket/myfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With