我正在使用一个 AWS Data Pipeline,它有一个 ShellCommandActivity,它将脚本 uri 设置为位于 s3 存储桶中的 bash 文件。 bash 文件将位于同一 s3 存储桶中的 python 脚本复制到 EmrCluster,然后该脚本尝试执行该 python 脚本。
这是我的管道导出:
{
"objects": [
{
"name": "DefaultResource1",
"id": "ResourceId_27dLM",
"amiVersion": "3.9.0",
"type": "EmrCluster",
"region": "us-east-1"
},
{
"failureAndRerunMode": "CASCADE",
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"pipelineLogUri": "s3://project/bin/scripts/logs/",
"scheduleType": "ONDEMAND",
"name": "Default",
"id": "Default"
},
{
"stage": "true",
"scriptUri": "s3://project/bin/scripts/RunPython.sh",
"name": "DefaultShellCommandActivity1",
"id": "ShellCommandActivityId_hA57k",
"runsOn": {
"ref": "ResourceId_27dLM"
},
"type": "ShellCommandActivity"
}
],
"parameters": []
}
这是 RunPython.sh:
#!/usr/bin/env bash
aws s3 cp s3://project/bin/scripts/Test.py ./
python ./Test.py
这是测试.py
__author__ = 'MrRobot'
import re
import os
import sys
import boto3
print "We've entered the python file"
从标准输出日志中我得到:
下载:s3://project/bin/scripts/Test.py 到 ./
从 Stdeer 日志中我得到:
python:无法打开文件“Test.py”:[Errno 2]没有这样的文件或目录
我也尝试用 python Test.py 替换 python ./Test.py,但得到了相同的结果。
如何让 AWS Data Pipeline 执行 Test.py 脚本。
EDIT
当我将 scriptUri 设置为 s3://project/bin/scripts/Test.py 时,出现以下错误
:
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第1行:author: 找不到命令
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第2行:导入:找不到命令
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第3行:导入:找不到命令
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第4行:导入:找不到命令
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第5行:导入:找不到命令
/mnt/taskRunner/output/tmp/df-0947490M9EHH2Y32694-59ed8ca814264f5d9e65b2d52ce78a53/ShellCommandActivityIdJiZP720170209T175934Attempt1_command.sh:第7行:打印:找不到命令
EDIT 2
将以下行添加到 Test.py
#!/usr/bin/env python
然后我收到以下错误:
错误:第 6 行,在 import boto3 中导入错误:没有名为 boto3 的模块
根据 @franklinsijo 的建议,我在 EmrCluster 上创建了一个具有以下值的引导操作:
s3://project/bin/scripts/BootstrapActions.sh
这是 BootstrapActions.sh
#!/usr/bin/env bash
sudo pip install boto3
这有效!!!!!!!