python-3.x - 如何使用 Boto3 向 AWS Batch 提交多个命令?

标签 python-3.x amazon-web-services docker aws-batch

我尝试使用 AWS Batch 和 boto3 通过 Docker 运行多个 shell 命令。当我尝试使用 & 符号提交多个命令时,如下所示,作业失败。

我的尝试

import boto3

client = boto3.client("batch")
response = client.submit_job(
    jobName='AndrewJob',
    jobQueue='AndrewJobQueue',
    jobDefinition='AndrewJobDefinition',
    containerOverrides={
        'command': 'ls & python myjob.py'.split(),
    },
    timeout = {'attemptDurationSeconds': 100}
)
print(response)

错误是:

ls: cannot access '&': No such file or directory

根据此处的 Docker 文档 https://docs.docker.com/engine/reference/builder/#cmd这篇文章在这里 docker run <IMAGE> <MULTIPLE COMMANDS>看起来这应该可以以 shell 形式实现。

最佳答案

Batch 的行为似乎与 subprocess.Popen 类似,它将命令作为一个命令执行,其中第一个参数是命令名称,其余参数是命令参数。我让它可以与 subprocess.Popen 一起使用,所以我打赌它可以与 Batch 一起使用:

subprocess.Popen(["/bin/bash", "-c", "ls && echo \"Hello world\""])

关于python-3.x - 如何使用 Boto3 向 AWS Batch 提交多个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59903393/

相关文章:

codeigniter - AWS SES codeigniter 邮件失败

docker compose 文件不工作 : replicas Additional property replicas is not allowed

python - 我在构建 Python3.6-buster 容器时收到 'apt-get upgrade' 命令失败错误

python - 如何从字母选择中返回字母表中最早的字母?

python - 使用python将S3 gzip源对象流式解压到S3目标对象?

python-3.x - 将 Picked 或 Joblib 预训练的 ML 模型加载到 Sagemaker 并作为端点托管

amazon-web-services - AWS Cloud Formation 模板失败,指定的映射表达式参数无效

docker - 二进制文件是用 'CGO_ENABLED=0' 编译的,go-sqlite3 需要 cgo 才能工作。这是一个 stub

python - Lua/Python 中的持久套接字连接

python - 如何获取发消息人的头像url?