Skip to content

Commit 0feaa6b

Browse files
committed
fix/derive the department name from the s3 path for csv to catalog
1 parent 8322c24 commit 0feaa6b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lambdas/csv_to_glue_catalog/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99
import re
1010
import unicodedata
11-
from os import getenv
1211
from pathlib import PurePosixPath
1312
from typing import Any
1413
from urllib.parse import unquote_plus
@@ -283,7 +282,6 @@ def handle_sqs_event(event: dict[str, Any]) -> dict[str, Any]:
283282
Returns:
284283
Dictionary with batchItemFailures for partial batch failure handling
285284
"""
286-
database_name = getenv("GLUE_DATABASE_NAME", "parking_user_uploads_db")
287285
sqs_records = event.get("Records", [])
288286
total_records = len(sqs_records)
289287
processed_count = 0
@@ -309,6 +307,14 @@ def handle_sqs_event(event: dict[str, Any]) -> dict[str, Any]:
309307
)
310308
logger.info(f"Processing file from message {message_id}: {s3_key}")
311309

310+
# Extract and normalize department from S3 path to construct database name
311+
department, _, _ = parse_s3_key(s3_key)
312+
normalized_dept = department.replace("-", "_")
313+
database_name = f"{normalized_dept}_user_uploads_db"
314+
logger.info(
315+
f"Using database '{database_name}' for department '{department}'"
316+
)
317+
312318
was_processed, was_skipped = process_single_event_record(
313319
s3_event_record, database_name
314320
)

0 commit comments

Comments
 (0)