Last active
June 15, 2020 07:45
-
-
Save yogendratamang48/1f02147a551ad4b8319a049d691ca759 to your computer and use it in GitHub Desktop.
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
""" | |
uploads file from `SOURCE_DIR` to S3. The path in S3 will follow | |
`TARGET_DIR` key name. | |
""" | |
import boto3 | |
from datetime import datetime | |
import os | |
from config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCES_KEY | |
session = boto3.Session( | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCES_KEY, | |
) | |
s3 = session.resource('s3') | |
BUCKET_NAME = "exports" | |
SOURCE_DIR = 'C:/Users/Yogendra/exports/20200508' | |
TARGET_DIR = f'{datetime.now().strftime("%Y%m%d")}' | |
for _file in os.listdir(SOURCE_DIR): | |
full_file_path = f"{SOURCE_DIR}/{_file}" | |
target_file_path = f"{TARGET_DIR}/{_file}" | |
print(f"Uploading: {full_file_path} to S3.. {target_file_path}") | |
s3.Bucket(BUCKET_NAME).upload_file(full_file_path, target_file_path) | |
print(f"Upload complete\n") | |
# print(f"Upload success") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment