-
-
Save philroche/bf62ff729bf3efdcbc9c1ab7bfe3bb43 to your computer and use it in GitHub Desktop.
AWS Bucket Lifecycle for AMI testing (delete after 7 days)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cat > lifecycle.json <<EOF | |
{ | |
"Rules": [ | |
{ | |
"Expiration": { | |
"Days": 7 | |
}, | |
"ID": "Expire, delete, and cancel", | |
"Prefix": "", | |
"Status": "Enabled", | |
"NoncurrentVersionExpiration": { | |
"NoncurrentDays": 7 | |
}, | |
"AbortIncompleteMultipartUpload": { | |
"DaysAfterInitiation": 2 | |
} | |
} | |
] | |
} | |
EOF | |
BUCKETS=`aws --output text s3api list-buckets | cut -f 3|grep jenkins|grep daily` | |
# View current lifecycle policy | |
for BUCKET in $BUCKETS ; do | |
echo $BUCKET | |
aws s3api get-bucket-lifecycle --bucket $BUCKET | |
echo | |
done | |
# Add 7d policy | |
for BUCKET in $BUCKETS ; do | |
echo $BUCKET | |
aws s3api put-bucket-lifecycle --bucket $BUCKET --lifecycle-configuration file://lifecycle.json | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment