bash - EMR 笔记本安装额外的库

标签 bash amazon-web-services jupyter-notebook libraries amazon-emr

我在通过我的 EMR 笔记本处理其他库时遇到了令人惊讶的困难。 EMR 的 AWS 接口(interface)允许我创建 Jupyter 笔记本并将它们附加到正在运行的集群。我想在其中使用其他库。通过 SSH 连接到机器并以 ec2-userroot 手动安装不会使这些库可供笔记本使用,因为它显然使用了 livy用户。引导操作为 hadoop 安装东西。我无法从笔记本安装,因为它的用户显然没有 sudogit 等,而且它可能无论如何都不会安装到 slaves。

为通过 EMR 界面创建的笔记本安装附加库的规范方法是什么?

最佳答案

为了举例,我们假设您需要在正在运行 的 EMR 集群上使用 librosa Python 模块。我们将使用 Python 2.7,因为过程更简单 - 保证 Python 2.7 在集群上,这是 EMR 的默认运行时。

创建安装包的脚本:

#!/bin/bash
sudo easy_install-2.7 pip
sudo /usr/local/bin/pip2 install librosa

并将其保存到您的主目录,例如/home/hadoop/install_librosa.sh。记下名称,我们稍后会用到它。

在下一步中,您将通过受 Amazon EMR docs 启发的另一个脚本来运行此脚本。 : emr_install.py。它使用 AWS Systems Manager 在节点上执行您的脚本。

import time
from boto3 import client
from sys import argv

try:
  clusterId=argv[1]
except:
  print("Syntax: emr_install.py [ClusterId]")
  import sys
  sys.exit(1)

emrclient=client('emr')

# Get list of core nodes
instances=emrclient.list_instances(ClusterId=clusterId,InstanceGroupTypes=['CORE'])['Instances']
instance_list=[x['Ec2InstanceId'] for x in instances]

# Attach tag to core nodes
ec2client=client('ec2')
ec2client.create_tags(Resources=instance_list,Tags=[{"Key":"environment","Value":"coreNodeLibs"}])

ssmclient=client('ssm')

    # Run shell script to install libraries

command=ssmclient.send_command(Targets=[{"Key": "tag:environment", "Values":["coreNodeLibs"]}],
                               DocumentName='AWS-RunShellScript',
                               Parameters={"commands":["bash /home/hadoop/install_librosa.sh"]},
                               TimeoutSeconds=3600)['Command']['CommandId']

command_status=ssmclient.list_commands(
  CommandId=command,
  Filters=[
      {
          'key': 'Status',
          'value': 'SUCCESS'
      },
  ]
)['Commands'][0]['Status']

time.sleep(30)

print("Command:" + command + ": " + command_status)

运行它:

python emr_install.py [cluster_id]

关于bash - EMR 笔记本安装额外的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54697280/

相关文章:

linux - 如何使用 bash 知道连接到每个 SSID 的客户端数量?

javascript - AWS IoT Core 连接被经过身份验证的 Cognito 用户拒绝并附有策略 [MQTT over WSS]

wordpress - 有什么方法可以将 AWS Cloudfront 设置为指向静态 IP 地址(托管在 GoDaddy 上的 WP)?

python - jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000 不工作

python - Octave isnan : not defined error using oct2py

linux - dig -x +short to file 没有 STDERR

linux - 如何在 bash shell 中格式化字符串?

bash - 是否可以逐行调试 bash 脚本?

java - aws.accessKeyId 和 aws.secretKey 未被读取

python - 如何在 IPython 循环期间内联显示 ndarray 图像?