def METHOD_NAME(nb_tag_value, bucket_name, tag_name, ssh_user, key_path):
    logging.info('Terminating EMR cluster and cleaning EMR config from S3 bucket')
    try:
        clusters_list = datalab.meta_lib.get_emr_list(nb_tag_value, 'Value')
        if clusters_list:
            for cluster_id in clusters_list:
                computational_name = ''
                client = boto3.client('emr')
                cluster = client.describe_cluster(ClusterId=cluster_id)
                cluster = cluster.get("Cluster")
                emr_name = cluster.get('Name')
                emr_version = cluster.get('ReleaseLabel')
                for tag in cluster.get('Tags'):
                    if tag.get('Key') == 'ComputationalName':
                        computational_name = tag.get('Value')
                datalab.actions_lib.s3_cleanup(bucket_name, emr_name, os.environ['project_name'])
                logging.info("The bucket {} has been cleaned successfully".format(bucket_name))
                datalab.actions_lib.terminate_emr(cluster_id)
                logging.info("The EMR cluster {} has been terminated successfully".format(emr_name))
                datalab.actions_lib.remove_kernels(emr_name, tag_name, nb_tag_value, ssh_user, key_path, emr_version,
                                                   computational_name)
                logging.info("{} kernels have been removed from notebook successfully".format(emr_name))
        else:
            logging.info("There are no EMR clusters to terminate.")
    except:
        sys.exit(1)
    logging.info("Stopping data engine cluster")
    try:
        cluster_list = []
        master_ids = []
        cluster_instances_list = datalab.meta_lib.get_ec2_list('dataengine_notebook_name', nb_tag_value)
        for instance in cluster_instances_list:
            for tag in instance.tags:
                if tag['Key'] == 'Type' and tag['Value'] == 'master':
                    master_ids.append(instance.id)
        for id in master_ids:
            for tag in datalab.meta_lib.get_instance_attr(id, 'tags'):
                if tag['Key'] == 'Name':
                    cluster_list.append(tag['Value'].replace(' ', '')[:-2])
        datalab.actions_lib.stop_ec2('dataengine_notebook_name', nb_tag_value)
    except:
        sys.exit(1)
    logging.info("Stopping notebook")
    try:
        datalab.actions_lib.stop_ec2(tag_name, nb_tag_value)
    except:
        sys.exit(1)