Orchestration of sender lambda, tagging of textract request, tagging of files, added textract detection capability

This commit is contained in:
Pankaj Katariya
2024-02-28 19:13:13 +05:30
parent a2659d0355
commit 71d05abc9a
2 changed files with 60 additions and 4 deletions
+28
View File
@@ -152,6 +152,27 @@ def start_textract_analysis_job(
else:
return job_id
# Function to get s3 object tags
def get_s3_object_tags(bucket_name, object_key):
try:
# Get object tags
response = s3_client.get_object_tagging(
Bucket=bucket_name,
Key=object_key
)
# Extract tags from the response and convert to dictionary
tags_list = response['TagSet']
tags_dict = {tag['Key']: tag['Value'] for tag in tags_list}
return tags_dict
except Exception as e:
logger.exception(f"Error: {e}")
print(f"Error: {e}")
return None
# AWS Lambda handler function
def lambda_handler(event, context):
@@ -223,6 +244,13 @@ def lambda_handler(event, context):
# Move file to stagging
move_file_within_s3(S3_BUCKET_NAME, source_path, destination_path)
# Read tags from file
tags_dict = get_s3_object_tags(S3_BUCKET_NAME,destination_path)
# check if key exist in tags_dict
if "batch_id" in tags_dict.keys():
JOB_TAG = JOB_TAG + "-" + tags_dict['batch_id']
job_id = ""
if PROCESS_TYPE == "ANALYSIS":