Orchestration of sender lambda, tagging of textract request, tagging of files, added textract detection capability
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user