aboutsummaryrefslogtreecommitdiffstats
path: root/src/extract_lambda.py
diff options
context:
space:
mode:
authorbulve-ad <78788030+bulve-ad@users.noreply.github.com>2024-08-23 17:25:29 +0100
committerGitHub <noreply@github.com>2024-08-23 17:25:29 +0100
commit8f75a47d01daf94999ee94a6c658adab6ca63c1d (patch)
tree64b5bb5010b9124ae612dcc7e7cb75400fa07241 /src/extract_lambda.py
parent30525f27ba1d20c65216cbe58a62953b8f1fe947 (diff)
parentf1e10e1a2f573c152b19a630577a71ce9aff2bb4 (diff)
downloadde-project-bentley-8f75a47d01daf94999ee94a6c658adab6ca63c1d.tar.gz
de-project-bentley-8f75a47d01daf94999ee94a6c658adab6ca63c1d.zip
Merge branch 'test/test_transform_lambda' into test/dataframes
Diffstat (limited to 'src/extract_lambda.py')
-rw-r--r--src/extract_lambda.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/extract_lambda.py b/src/extract_lambda.py
index 24f0981..b20c99d 100644
--- a/src/extract_lambda.py
+++ b/src/extract_lambda.py
@@ -99,24 +99,35 @@ def connect_to_database() -> Connection:
raise DBConnectionException("Failed to connect to database")
-def extract_bucket(client=boto3.client("s3")):
+def extract_bucket(client=None):
+ if client is None:
+ client = boto3.client("s3")
response = client.list_buckets()
extract_bucket_filter = [
bucket["Name"] for bucket in response["Buckets"] if "extract" in bucket["Name"]
]
+ if not extract_bucket_filter:
+ raise ValueError("No extract_bucket found")
+
return extract_bucket_filter[0]
-def list_existing_s3_files(bucket_name=extract_bucket(), client=boto3.client("s3")):
+def list_existing_s3_files(bucket_name=None, client=None):
"""Creates a dictionary and populates it with the
results of listing the contents of the s3 bucket, then
returns the populated dictionary
"""
+
logging.info("Listing existing S3 files")
existing_files = {}
try:
+ if client is None:
+ client = boto3.client("s3")
+ if bucket_name is None:
+ bucket_name = extract_bucket(client)
+
response = client.list_objects_v2(Bucket=bucket_name)
if "Contents" in response:
@@ -132,8 +143,11 @@ def list_existing_s3_files(bucket_name=extract_bucket(), client=boto3.client("s3
logger.error("The bucket is empty")
return None
- except ClientError as e:
- logger.error(f"Error listing S3 objects: {e}")
+ except ValueError as ve:
+ logger.error(f"Error listing S3 objects: {ve}")
+ raise
+ except ClientError as ce:
+ logger.error(f"Error listing S3 objects: {ce}")
return existing_files
git.ajschof.me — hosted by ajschofield — powered by cgit