Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upload static file dir recursively to Amazon S3 using python
from os import listdir
from os.path import isdir
from simples3 import S3Bucket # pip install simples3
root = "../static"
exclude = [".DS_Store"]
A = "access key"
B = "secret key"
bucket = "guidenext"
s3 = S3Bucket(bucket,
access_key=A,
secret_key=B,
base_url="http://%s.s3.amazonaws.com" % bucket)
def upload_file(src):
print "- uploading %s" % src
f = open(src)
s3.put(src.replace(root, "admin"), f.read())
def upload_dir(path):
for f in listdir(path):
if f not in exclude:
if isdir("%s/%s" % (path, f)) is True:
upload_dir("%s/%s" % (path, f))
else:
upload_file("%s/%s" % (path, f))
upload_dir(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.