in src/blog-extract.py [0:0]
def lambda_handler(event, context):
# This code gets triggered by a object upload in S3 Bucket.
# It sends object from S3 bucket to textract for key-value extracttion.
# In successful extraction it stores key-value pairs in S3 as CSV file.
# In case of failures it prompts message.
print(event)
obj=event['Records'][0]['s3']['object']['key']
print(obj)
bucket=event['Records'][0]['s3']['bucket']['name']
try:
key_map, value_map, block_map, line_val = get_kv_map(obj, bucket)
# Get Key Value relationship
kvs = get_kv_relationship(key_map, value_map, block_map)
kvs['PROCEDURE'] = line_val
print("\n\n== FOUND KEY : VALUE pairs ===\n")
print_kvs(kvs)
# Add to Queue for validation
queue = os.environ['allqueue']
print(queue)
msg = sqs_client.send_message(QueueUrl=queue,
MessageBody=str(kvs))
print(msg)
except Exception as e:
print("Failed in processing file")
print(e.message)
return {
'statusCode': 200,
'body': json.dumps('Success!')
}