Skip to content

Instantly share code, notes, and snippets.

@reecestart
Created December 3, 2018 05:08
Show Gist options
  • Save reecestart/9f7963a21c12e07d13bbb0607d7e7979 to your computer and use it in GitHub Desktop.
Save reecestart/9f7963a21c12e07d13bbb0607d7e7979 to your computer and use it in GitHub Desktop.
Gets all S3 Buckets and creates an Intelligent Tiering Lifecycle Rule on all of them.
import boto3
from datetime import date
from datetime import datetime
today = date.today()
today = datetime.combine(today, datetime.min.time())
client = boto3.client('s3')
# Get all buckets
response = client.list_buckets()
Buckets = (response['Buckets'])
BucketNames = []
for i in Buckets:
BucketNames.append(i['Name'])
for i in BucketNames:
response = client.put_bucket_lifecycle_configuration(
Bucket=i,
LifecycleConfiguration={
'Rules': [
{
'Prefix': '',
'Status': 'Enabled',
'Transitions': [
{
'Days': 0,
'StorageClass': 'INTELLIGENT_TIERING'
},
]
}
]
}
)
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print('Bucket ' + i + ' has had Intelligent Tiering enabled.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment