Skip to content

Instantly share code, notes, and snippets.

@Dunedan
Last active July 25, 2022 23:02
Show Gist options
  • Save Dunedan/c98602a956e3958935c5 to your computer and use it in GitHub Desktop.
Save Dunedan/c98602a956e3958935c5 to your computer and use it in GitHub Desktop.
Small bash script to get the lifecycle transitions of all buckets in an AWS account.
#!/bin/bash
# Licensed under CC0 <https://creativecommons.org/publicdomain/zero/1.0/>
AWS_PROFILE="default"
BUCKETS=$(aws --profile $AWS_PROFILE s3api list-buckets --query 'Buckets[*].Name' --output text)
echo -e "bucket name\tstatus of the transition\tprefix the transition applies to\tdays after which the transition applies\tto storage class\tdelete after days\tdescription"
for bucket in $BUCKETS; do
TRANSITION=$(aws --profile $AWS_PROFILE s3api get-bucket-lifecycle --bucket $bucket --query 'Rules[*][Status, Prefix, Transition.Days, Transition.StorageClass, Expiration.Days, ID]' --output text 2> /dev/null)
if [ "$?" = "255" ]; then
echo -e "$bucket\tNone"
else
echo "$TRANSITION" | while read line; do
echo -e "$bucket\t$line"
done
fi
done
@obazoud
Copy link

obazoud commented May 17, 2016

A "," is missing after "Expiration.Days".
Thanks to share your script.

@Dunedan
Copy link
Author

Dunedan commented Mar 24, 2017

Thanks for pointing out. Thanks to non existent notifications for gists I saw your comment just now. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment