Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save obazoud/6c275369c1581d4ec1a36db804141aa5 to your computer and use it in GitHub Desktop.

Select an option

Save obazoud/6c275369c1581d4ec1a36db804141aa5 to your computer and use it in GitHub Desktop.

Revisions

  1. @Dunedan Dunedan created this gist Oct 27, 2015.
    17 changes: 17 additions & 0 deletions aws-s3-get-bucket-lifecycles.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash

    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