It's very time consuming to get objects from Glacier so I decided to use S3 IA storage class instead. I need to list all the objects in my bucket that have Glacier storage class (I configured it via LifeCycle policy) and to change it to S3 IA.
Is there any script or a tool for that?
You can do that using list-objects
list-objects
will return the StorageClass
, in your case you want to filter for values where it is GLACIER
aws s3api list-objects --bucket %bucket_name% --query 'Contents[?StorageClass==`GLACIER`]'
What you want then is to get only the list of Key that matches
aws s3api list-objects --bucket %bucket_name% --query 'Contents[?StorageClass==`GLACIER`][Key]' --output text
Then you will need to copy the object with changing the storage class of the Key
aws s3api list-objects --bucket %bucket_name% --query 'Contents[?StorageClass==`GLACIER`][Key]' --output text
| xargs -I {} aws s3 cp s3://bucket_name/{} s3://bucket_name/{} --storage-class STANDARD_IA
and ... if you need to run this from Powershell in windows, I had to do this:
aws s3api list-objects --bucket Your_Bucket --query 'Contents[?StorageClass==`STANDARD`][Key]' --output text | foreach { aws s3 cp s3://Your_Bucket/$_ s3://Your_Bucket/$_ --storage-class REDUCED_REDUNDANCY }
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