def invoke_model(event, context):
    status_code = 200
    try:
        event_body = event['body']
        payload = json.loads(event_body)
        rows = payload['data']
        body = ''
        for row in rows:
            model_name = row[1]
            body = ((((body + row[2]) + ',') + row[3]) + '\n')
        client = boto3.client('sagemaker-runtime')
        response = client.invoke_endpoint(EndpointName=model_name, Body=body.encode('utf-8'), ContentType='text/csv')
        predictions = response['Body'].read().decode('utf-8')
        i = 0
        array_of_rows_to_return = []
        for prediction in iter(predictions.splitlines()):
            row_to_return = [i, prediction]
            array_of_rows_to_return.append(row_to_return)
            i = (i + 1)
        json_compatible_string_to_return = json.dumps({'data': array_of_rows_to_return})
    except Exception as err:
        status_code = 400
        print(err)
        json_compatible_string_to_return = str(err)
    return {'statusCode': status_code, 'body': json_compatible_string_to_return}
def invoke_model(event, context):
    status_code = 200
    try:
        event_body = event['body']
        payload = json.loads(event_body)
        rows = payload['data']
        body = 
        for row in rows:
            model_name = row[1]
            body = ((((body + row[2]) + ',') + row[3]) + '\n')
        client = boto3.client('sagemaker-runtime')
        response = client.invoke_endpoint(EndpointName=model_name, Body=body.encode('utf-8'), ContentType='text/csv')
        predictions = response['Body'].read().decode('utf-8')
        i = 0
        array_of_rows_to_return = []
        for prediction in iter(predictions.splitlines()):
            row_to_return = [i, prediction]
            array_of_rows_to_return.append(row_to_return)
            i = (i + 1)
        json_compatible_string_to_return = json.dumps({'data': array_of_rows_to_return})
    except Exception as err:
        status_code = 400
        print(err)
        json_compatible_string_to_return = str(err)
    return {'statusCode': status_code, 'body': json_compatible_string_to_return}