From c62901504e23022b70bc993b9db93b8a78c21bf3 Mon Sep 17 00:00:00 2001 From: Joel Balcaen Date: Fri, 5 Apr 2024 13:27:07 -0300 Subject: [PATCH] add fetch file logging --- lambdas/rich_pdf_ingestion/src/index.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lambdas/rich_pdf_ingestion/src/index.py b/lambdas/rich_pdf_ingestion/src/index.py index d7811e0..a35b8bd 100644 --- a/lambdas/rich_pdf_ingestion/src/index.py +++ b/lambdas/rich_pdf_ingestion/src/index.py @@ -2,7 +2,7 @@ import os import boto3 from pypdf import PdfReader -import json +from botocore.exceptions import NoCredentialsError, BotoCoreError, ClientError OBJECT_CREATED = "ObjectCreated" @@ -30,17 +30,17 @@ def fetch_file(bucket, key): s3 = boto3.client("s3") local_filename = f"/tmp/{key.split('/')[-1]}" - - s3.download_file(bucket, key, local_filename) - # except NoCredentialsError as e: - # print(e) - # raise e - # except BotoCoreError as e: - # print(e) - # raise e - # except ClientError as e: - # print(e) - # raise e + try: + s3.download_file(bucket, key, local_filename) + except NoCredentialsError as e: + print(e) + raise e + except BotoCoreError as e: + print(e) + raise e + except ClientError as e: + print(e) + raise e return local_filename @@ -56,6 +56,7 @@ def lambda_handler(event, context): if eventName.startswith(OBJECT_CREATED): local_filename = fetch_file(bucket, key) + # collection_name = bucket + "-" # collection_name += os.path.dirname(key).replace("/", "-")