in deploy_code/multipagepdfa2i_analyzepdf/lambda_function.py [0:0]
def lambda_handler(event, context):
for record in event["Records"]:
body = json.loads(record["body"])
# body looks like:
# {
# "bucket": "",
# "wip_key": "",
# "id": "",
# "key": ""
# }
if body["wip_key"] == "single_image":
body["process_key"] = body["key"]
body["human_loop_id"] = body["id"] + "i0"
body["s3_location"] = "wip/" + body["id"] + "/0.png/ai/output.json"
else:
body["process_key"] = "wip/" + body["id"] + "/" + body["wip_key"] + ".png"
body["human_loop_id"] = body["id"] + "i" + body["wip_key"]
body["s3_location"] = body["process_key"] + "/ai/output.json"
print("process_key:", body["process_key"])
print("human_loop_id:", body["human_loop_id"])
print("s3_location:", body["s3_location"])
response, need_to_human_review = run_analyze_document(body)
kv_list = extract_data(response)
write_ai_response_to_bucket(body, kv_list)
if need_to_human_review is True:
response = dump_task_token_in_dynamodb(body)
if need_to_human_review is False:
response = invoke_to_get_back_to_stepfunction(body)
client = boto3.client('sqs')
response = client.delete_message(
QueueUrl=os.environ['sqs_url'],
ReceiptHandle=record["receiptHandle"]
)
return "all_done"