def lambda_handler()

in functions/DetectAnomaliesFunction/putItemInDynamoDb.py [0:0]


def lambda_handler(event, context):
    payload = event['Input']['Payload']
    timestamp = datetime.datetime.now().isoformat()

    table = dynamodb.Table(DYNAMODB_TABLE_NAME)
    item = {}
    item['CameraId'] = payload['CameraId']
    item['DateTime'] = timestamp
    item['AssemblyLineId'] = payload['AssemblyLineId']
    item['ImageUrl'] = payload['ImageUrl']
    item['ImageId'] = payload['ImageId']
    item['IsAnomalous'] = payload['DetectAnomalyResult']['IsAnomalous']
    item['Confidence'] = Decimal(payload['DetectAnomalyResult']['Confidence'])

    try:
        # write the record to the database
        response = table.put_item(Item=item)
        response['ImageDetails'] = item
        return response

    except Exception as e:
        print(e)
        raise e