def deploy_model(event, context):
    status_code = 200
    try:
        event_body = event['body']
        payload = json.loads(event_body)
        rows = payload['data']
        for row in rows:
            row_number = row[0]
            model_name = row[1]
            model_data_url = row[2]
        client = boto3.client('sagemaker')
        ECR_PATH = os.environ['training_image_ecr_path']
        SAGEMAKER_ROLE_ARN = os.environ['sagemaker_role_arn']
        response = client.create_model(ModelName=model_name, PrimaryContainer={'Image': ECR_PATH, 'ModelDataUrl': model_data_url}, ExecutionRoleArn=SAGEMAKER_ROLE_ARN)
        print(response)
        print('now trying to create endpoint config...')
        response = client.create_endpoint_config(EndpointConfigName=model_name, ProductionVariants=[{'VariantName': 'variant-1', 'ModelName': model_name, 'InitialInstanceCount': 1, 'InstanceType': 'ml.t2.medium'}])
        print(response)
        print('now trying to create the endpoint...')
        response = client.create_endpoint(EndpointName=model_name, EndpointConfigName=model_name)
        endpoint_arn = response['EndpointArn']
        print(endpoint_arn)
        array_of_rows_to_return = []
        row_to_return = [0, endpoint_arn]
        array_of_rows_to_return.append(row_to_return)
        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 deploy_model(event, context):
    status_code = 200
    try:
        event_body = event['body']
        payload = json.loads(event_body)
        rows = payload['data']
        for row in rows:
            row_number = row[0]
            model_name = row[1]
            model_data_url = row[2]
        client = boto3.client('sagemaker')
        ECR_PATH = os.environ['training_image_ecr_path']
        SAGEMAKER_ROLE_ARN = os.environ['sagemaker_role_arn']
        response = client.create_model(ModelName=model_name, PrimaryContainer={'Image': ECR_PATH, 'ModelDataUrl': model_data_url}, ExecutionRoleArn=SAGEMAKER_ROLE_ARN)
        print(response)
        print('now trying to create endpoint config...')
        response = client.create_endpoint_config(EndpointConfigName=model_name, ProductionVariants=[{'VariantName': 'variant-1', 'ModelName': model_name, 'InitialInstanceCount': 1, 'InstanceType': 'ml.t2.medium'}])
        print(response)
        print('now trying to create the endpoint...')
        response = client.create_endpoint(EndpointName=model_name, EndpointConfigName=model_name)
        endpoint_arn = response['EndpointArn']
        print(endpoint_arn)
        array_of_rows_to_return = []
        row_to_return = [0, endpoint_arn]
        array_of_rows_to_return.append(row_to_return)
        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}