Skip to content

Instantly share code, notes, and snippets.

@sbalnojan
Last active May 22, 2019 12:04
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 sbalnojan/27ce558bddcf75a0dd707775155a150e to your computer and use it in GitHub Desktop.
Save sbalnojan/27ce558bddcf75a0dd707775155a150e to your computer and use it in GitHub Desktop.
Mini Cli to copy tree to S3
import s3fs
import fire
import os
class S3CopyMachine(object):
"""Copy to S3 via s3fs."""
def to_s3(self, local_bucket, s3_bucket):
fs = s3fs.S3FileSystem(anon=False) # connecting to S3
main_root = os.path.join(os.getcwd(),local_bucket)
for root, subdirs, files in os.walk(main_root):
print('--\nroot = ' + root)
for subdir in subdirs:
print('\t- subdirectory ' + subdir)
for filename in files:
file_path = os.path.join(root, filename)
rel_path = os.path.relpath(file_path, main_root)
print('\t- file %s (full path: %s, rel. path: %s)' % (filename, file_path, rel_path))
fs.put(file_path,s3_bucket + "/" + rel_path)
return 0
if __name__ == '__main__':
fire.Fire(S3CopyMachine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment