app.py 672 B

1234567891011121314151617181920212223
  1. import os
  2. import boto3
  3. from botocore.client import Config
  4. ACCESS_KEY_ID = os.environ.get('ACCESS_KEY_ID')
  5. ACCESS_SECRET_KEY = os.environ.get('ACCESS_SECRET_KEY')
  6. BUCKET_NAME = 'uploading-from-local-dir'
  7. path = '/home/ubuntu/workspace/files'
  8. print(os.listdir(path))
  9. for filename in os.listdir(path):
  10. data = open(path + '/' + filename, 'rb')
  11. s3 = boto3.resource(
  12. 's3',
  13. aws_access_key_id=ACCESS_KEY_ID,
  14. aws_secret_access_key=ACCESS_SECRET_KEY,
  15. config=Config(signature_version='s3v4')
  16. )
  17. s3.Bucket(BUCKET_NAME).put_object(Key=filename, Body=data)
  18. os.remove(path + '/' + filename)
  19. print("File Removed!")
  20. print ("Done")