Skip to content

Instantly share code, notes, and snippets.

@rcj4747
Created November 9, 2017 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rcj4747/69adc79013c87c990953de7320f04447 to your computer and use it in GitHub Desktop.
Save rcj4747/69adc79013c87c990953de7320f04447 to your computer and use it in GitHub Desktop.
AWS Bucket Lifecycle for AMI testing (delete after 7 days)
#!/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