def store_data_prediction()

in source/lambda/model-invocation/index.py [0:0]


def store_data_prediction(output_dict, metadata):
    firehose_delivery_stream = STREAM_NAME
    firehose = boto3.client('firehose', region_name=os.environ['AWS_REGION'])

    # Extract anomaly score and classifier prediction, if they exist
    fraud_pred = output_dict["fraud_classifier"]["prediction"] if 'fraud_classifier' in output_dict else ""
    anomaly_score = output_dict["anomaly_detector"]["score"] if 'anomaly_detector' in output_dict else ""

    record = ','.join(metadata + [str(fraud_pred), str(anomaly_score)]) + '\n'

    success = firehose.put_record(
        DeliveryStreamName=firehose_delivery_stream, Record={'Data': record})
    if success:
        logger.info("Record logged: {}".format(record))
    else:
        logger.warning("Record delivery failed for record: {}".format(record))