2014-05-08 43 views
12

我有幾個存儲在Amazon S3中的對象,其內容類型需要從text/html更改爲application/rss+xml。我認爲應該可以使用複製命令來完成此操作,爲源和目標指定相同的路徑。我試圖做到這一點使用AWS CLI工具,但我得到這個錯誤:如何使用aws cli更改對象的內容類型?

$ 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. 

如果我指定源和目的地的不同路徑,我沒有得到錯誤:

$ 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 

即使命令成功完成,index2.html對象也會使用text/html內容類型創建,而不是我指定的application/rss+xml類型。

我該如何修改這個命令行才能使其工作?

+1

剛剛看到[此問題](https://github.com/aws/aws-cli/issues/652#issuecomment-41213226)報告了同樣的問題。該線程包含了一些解決方法,所以我會看看我如何與他們相處。 – nelstrom

回答

8

有可能使用低級別s3api使這一變化:

$ 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

的問題只是不能夠指定--metadata-directive。感謝您指出open issue/feature request,nelstrom!

+0

如何對具有特定擴展名的多個對象執行此操作? – bart

+0

可能有更清晰的方法,但是您可以在文件中列出對象,然後讀取所有行並在每行上執行上述命令,因此上面的代碼如下所示: 'while read line; do copy-object --bucket archive --content-type「application/rss + xml」--copy-source archive/$ line.html --key $ line.html --metadata-directive「REPLACE」;完成 Cawb07