2017-08-14 96 views
1

有沒有辦法使用一個單一的put-object-tagging cli命令將標記(或一組標記)應用於S3目錄中的所有對象?AWS S3 cli - 標記目錄中的所有對象

也就是說,如果我有兩個文件(test0.txttest.txt)我可以做運行以下兩個命令:

>aws s3api put-object-tagging --bucket mybucket --key foo/bar/test0.txt --tagging 'TagSet=[{Key=colour,Value=blue}]' 
>aws s3api put-object-tagging --bucket mybucket --key foo/bar/test1.txt --tagging 'TagSet=[{Key=colour,Value=blue}]' 

當試圖通過文件夾本身作爲--key選項我得到以下錯誤(因爲它必須引用單個對象):

>aws s3api put-object-tagging --bucket mybucket --key foo/bar/ --tagging 'TagSet=[{Key=colour,Value=blue}] 
An error occurred (NoSuchKey) when calling the PutObjectTagging operation: The specified key does not exist. 

是否有解決方法?

回答

2

S3中沒有目錄的概念。這是一個原油的方式達到你想要的。其他海報可能有更好的解決方案。以下解決方案首先獲取文件夾中的所有對象,然後爲每個對象調用put-object-tagging注意:我沒有測試這個解決方案。

aws s3api list-objects --bucket mybucket --query 'Contents[].{Key:Key}' 
    --output text | grep foo/bar/ | xargs aws s3api put-object-tagging 
    --bucket mybucket --tagging 'TagSet=[{Key=colour,Value=blue}]' --key