如何使 AWS Data Pipeline ShellCommandActivity 脚本执行 python 文件

2024-02-16

我正在使用一个 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

这有效!!!!!!!


配置 ShellCommandActivity 为

  • 传递 python 文件的 S3 Uri 路径作为Script Uri.
  • 添加 shebang 行#!/usr/bin/env python在里面 脚本。
  • If any non-default python libraries are used in the script, install them on the target resource.
    • If runsOn选择后,将安装命令添加为引导动作 http://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-bootstrap.html用于 EMR 资源。
    • If workerGroup选择后,安装所有库工人组 http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-how-task-runner-user-managed.html在管道激活之前。

使用任一pip or easy_install安装 python 模块。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使 AWS Data Pipeline ShellCommandActivity 脚本执行 python 文件 的相关文章

随机推荐