def train_and_generate_recommendations(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]
            _input_table_name = row[1]
            _output_table_name = row[2]
        client = boto3.client('sagemaker')
        bucket = os.environ['s3_bucket']
        prefix = ('training-job-' + time.strftime('%Y%m%d%H%M%S'))
        s3_output_location = 's3://{}/'.format(bucket)
        print(s3_output_location)
        training_job_name = prefix
        TRAINING_IMAGE_ECR_PATH = os.environ['training_image_ecr_path']
        SAGEMAKER_ROLE_ARN = os.environ['sagemaker_role_arn']
        response = client.create_training_job(TrainingJobName=training_job_name, HyperParameters=dict(input_table_name=_input_table_name, output_table_name=_output_table_name, region=os.environ['region']), AlgorithmSpecification={'TrainingImage': TRAINING_IMAGE_ECR_PATH, 'TrainingInputMode': 'File'}, RoleArn=SAGEMAKER_ROLE_ARN, OutputDataConfig={'S3OutputPath': s3_output_location}, ResourceConfig={'InstanceType': 'ml.m5.xlarge', 'InstanceCount': 1, 'VolumeSizeInGB': 10}, StoppingCondition={'MaxRuntimeInSeconds': 10000})
        training_job_arn = response['TrainingJobArn']
        print(training_job_arn)
        array_of_rows_to_return = []
        row_to_return = [0, training_job_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 train_and_generate_recommendations(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]
            _input_table_name = row[1]
            _output_table_name = row[2]
        client = boto3.client('sagemaker')
        bucket = os.environ['s3_bucket']
        prefix = ('training-job-' + time.strftime('%Y%m%d%H%M%S'))
        s3_output_location = 's3://{}/'.format(bucket)
        print(s3_output_location)
        training_job_name = prefix
        TRAINING_IMAGE_ECR_PATH = os.environ['training_image_ecr_path']
        SAGEMAKER_ROLE_ARN = os.environ['sagemaker_role_arn']
        response = client.create_training_job(TrainingJobName=training_job_name, HyperParameters=dict(input_table_name=_input_table_name, output_table_name=_output_table_name, region=os.environ['region']), AlgorithmSpecification={'TrainingImage': TRAINING_IMAGE_ECR_PATH, 'TrainingInputMode': 'File'}, RoleArn=SAGEMAKER_ROLE_ARN, OutputDataConfig={'S3OutputPath': s3_output_location}, ResourceConfig={'InstanceType': 'ml.m5.xlarge', 'InstanceCount': 1, 'VolumeSizeInGB': 10}, StoppingCondition={'MaxRuntimeInSeconds': 10000})
        training_job_arn = response['TrainingJobArn']
        print(training_job_arn)
        array_of_rows_to_return = []
        row_to_return = [0, training_job_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}