Created
June 26, 2017 02:05
-
-
Save MattHealy/5d7907d24f66c4b84f6a891b012eff1b to your computer and use it in GitHub Desktop.
Python script to encrypt all existing objects in an S3 bucket
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
#!/usr/bin/env python | |
# set SSE on all existing objects | |
#usage: encrypt_all_objects.py bucketname | |
import sys | |
import boto | |
from boto import connect_s3 | |
from boto.s3 import connect_to_region | |
from boto.s3.connection import S3Connection, OrdinaryCallingFormat | |
bucketname = sys.argv[1] | |
s3 = connect_to_region( | |
'ap-southeast-2', | |
is_secure=True, | |
calling_format = OrdinaryCallingFormat() | |
) | |
bucket = s3.get_bucket(bucketname) | |
keys = bucket.list() | |
for k in keys: | |
print(k.key) | |
k.copy(bucketname, k.key, encrypt_key=True, preserve_acl=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment