def lambda_handler()

in workshops/AI_ML_services_workshop_information/lambda_code/ai_ml_services_lambda.py [0:0]


def lambda_handler(event, context):
    #uncomment to log event info
    #logging.info(json.dumps(event))

    filename=event['Records'][0]['s3']['object']['key']
    filename_basename=os.path.basename(filename)

    #content=read_in_file_from_s3(NOTIFICATION_BUCKET_NAME,filename)
    content=call_textract(NOTIFICATION_BUCKET_NAME,filename)
    content_2=call_comprehehend_medical(the_input=content,call_type='detect_entities_v2') # .decode("utf-8") decode to prevent error
    custom_predictions=call_comprehend(the_input=content) #.decode("utf-8")
    content_3=copy.deepcopy(content_2) #make copy to avoid modifying original dictionary
    content_3['Comprehend_Detected_Entities']=custom_predictions
    content_3['Raw Text']=content
    content_4=content_3


    #export final output
    #logging.info(json.dumps(content_4))
    put_file_in_s3(f'''{filename_basename}_out''',json.dumps(content_4),OUTPUT_BUCKET_NAME)


    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }