Skip to content

Instantly share code, notes, and snippets.

@MattHealy
Created June 26, 2017 02:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save MattHealy/5d7907d24f66c4b84f6a891b012eff1b to your computer and use it in GitHub Desktop.
Save MattHealy/5d7907d24f66c4b84f6a891b012eff1b to your computer and use it in GitHub Desktop.
Python script to encrypt all existing objects in an S3 bucket
#!/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