Skip to content

Instantly share code, notes, and snippets.

@kisna72
Last active July 26, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kisna72/ec1090acb26c1054300bd41f4e15fe16 to your computer and use it in GitHub Desktop.
Save kisna72/ec1090acb26c1054300bd41f4e15fe16 to your computer and use it in GitHub Desktop.
Code to upload files to AWS
import boto3
import botocore
import os,sys
ACCESS_KEY = os.environ["AWS_ACCESS_KEY_ID"]
SECRET_KEY = os.environ["AWS_SECRET_ACCESS_KEY"]
bucket_name = "foo"
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
for key in bucket.objects.all():
print(key.key)
base_path = r"C:\aws_file_backup\test_files"
all_files = []
for root, dirs, files in os.walk(base_path):
for file in files:
full_file_name = os.path.join(base_path, root, file)
partial_file_name = full_file_name[19:]
partial_file_name = partial_file_name.replace("\\" , "/")
print(full_file_name)
print(partial_file_name)
tup = (full_file_name, partial_file_name)
all_files.append(tup)
for f in all_files:
s3.Object(bucket_name , f[1]).put(Body = open(f[0], 'rb'))
print("Done Adding One.")
print(f[1])
print("Transfer Complete. ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment