-
-
Save minasys/865dc78e37d89c4f0eebfc143ef77b56 to your computer and use it in GitHub Desktop.
enable mfa-delete on a bucket
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
import boto3 | |
from botocore.exceptions import ClientError | |
s3_client = boto3.client('s3') | |
s3_bucket = boto3.resource('s3') | |
bucket_name = raw_input('Enter the name of the bucket that you want to enable MFA-delete on: ') | |
mfa_token = raw_input('Enter your MFA serial number and token code, e.g. <deviceSerialNumber> <tokenCode>: ') | |
try: | |
s3_bucket.meta.client.head_bucket(Bucket=bucket_name) | |
except ClientError as e: | |
if int(e.response['Error']['Code']) == 404: | |
print 'Bucket does not exist' | |
exit() | |
try: | |
s3_client.put_bucket_versioning(Bucket = bucket_name, | |
MFA = mfa_token, | |
VersioningConfiguration = { | |
'MFADelete' : 'Enabled', | |
'Status' : 'Enabled' | |
} | |
) | |
except ClientError as e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment