我尝试使用 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/