Created
December 3, 2018 05:08
-
-
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.
This file contains hidden or 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
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