-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload_simulation_script.py
More file actions
35 lines (27 loc) · 1.07 KB
/
upload_simulation_script.py
File metadata and controls
35 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
This script uploads CSV files from a local folder to an AWS S3 bucket,
excluding a specific file, and waits for 30 seconds between uploads."""
import os
import time
import boto3
from dotenv import load_dotenv
load_dotenv() # Load environment variables from .env file
# AWS S3 configuration
BUCKET_NAME = os.getenv("PROJECT_ID")
S3_PREFIX = "data/input/"
LOCAL_FOLDER = "data"
EXCLUDED_FILE = "customer_churn_0.csv"
# Initialize S3 client
s3 = boto3.client("s3")
# Upload files with delay
for filename in os.listdir(LOCAL_FOLDER):
if filename.endswith(".csv") and filename != EXCLUDED_FILE:
local_path = os.path.join(LOCAL_FOLDER, filename)
s3_key = f"{S3_PREFIX}{filename}" # pylint: disable=invalid-name
try:
s3.upload_file(local_path, BUCKET_NAME, s3_key)
print(f"✅ Uploaded {filename} to s3://{BUCKET_NAME}/{s3_key}")
except Exception as e: # pylint: disable=broad-except
print(f"❌ Failed to upload {filename}: {e}")
print("⏳ Waiting 30 seconds before next upload...")
time.sleep(30)