Last active
November 8, 2016 03:42
-
-
Save inscapist/31641dd227d785aa24235c1fbc26a347 to your computer and use it in GitHub Desktop.
privatize s3 buckets that were made public, using boto. "pip install boto"
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
#!/usr/bin/env python | |
#remove public read right for all keys within a directory | |
#usage: ./privatize-s3-bucket.sh bucketName folderName | |
# env AWS_ACCESS_KEY_ID=$aws_key \ | |
# AWS_SECRET_ACCESS_KEY=$aws_secret \ | |
# ./privatize-s3-bucket.sh cwd-p2p-uploads document_uploads/user | |
import sys | |
import boto | |
bucketname = sys.argv[1] | |
dirname = sys.argv[2] | |
s3 = boto.connect_s3() | |
bucket = s3.get_bucket(bucketname) | |
keys = bucket.list(dirname) | |
for k in keys: | |
# options are 'private', 'public-read' | |
# 'public-read-write', 'authenticated-read' | |
k.set_acl('private') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment