EMR笔记本安装其他库

Wal*_*Cat 16 bash amazon-web-services libraries amazon-emr jupyter-notebook

我通过我的EMR笔记本使用其他库时非常困难.EMR的AWS界面允许我创建Jupyter笔记本并将它们附加到正在运行的集群.我想在其中使用其他库.SSH进入机器并手动安装ec2-userroot不会使库可用于笔记本,因为它显然使用了livy用户.引导操作安装的东西hadoop.我无法从笔记本电脑安装,因为它的用户显然没有sudo,git等等,它可能不会安装到奴隶反正.

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

Luk*_*ski 2

举个例子,我们假设您需要librosaPython 模块来运行EMR 集群。我们将使用 Python 2.7,因为过程更简单 - Python 2.7 保证位于集群上,并且这是 EMR 的默认运行时。

创建一个安装该包的脚本:

#!/bin/bash
sudo easy_install-2.7 pip
sudo /usr/local/bin/pip2 install librosa
Run Code Online (Sandbox Code Playgroud)

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

在下一步中,您将通过受Amazon EMR 文档启发的另一个脚本运行此脚本: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)
Run Code Online (Sandbox Code Playgroud)

运行它:

python emr_install.py [cluster_id]