在S3存储桶上运行AWS Batch作业的JAR文件。

huangapple go评论55阅读模式
英文:

Running AWS Batch Job on the JAR artifact from S3 bucket

问题

  1. amazon:linux镜像上没有安装AWS客户端,因此无法在作业定义中使用aws s3 cp命令将可执行文件复制到EC2实例上。出现以下错误:
CannotStartContainerError: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "aws": executable file not found in $PATH: unknown
  1. 使用wget命令可以从S3桶下载可执行文件到EC2,但在作业定义的Bash命令中,无法区分下一个命令。比如wget <source-url> && java -jar executable.jar,这里尝试处理Bash中的'&&',尝试多种方式将两个命令放在单个Bash行中,但都没有成功。出现以下错误:
    wget: unable to resolve host address java <- 在作业定义的Bash中不使用'&'符号
    wget: unable to resolve host address ‘&amp;&amp;’ <- 在Bash命令中使用'&'等分隔符来分隔命令时发生的错误。
英文:

In one of specific requirement, we need to use a Jar executable provided by other team in one of S3 bucket in a aws batch. The plan is to configure a aws batch which will spawn a EC2 instance, will copy the jar file from the s3 bucket and will run the java -jar command on the same jar with intended command line parameters.

Problem is,

  1. the amazon:linux image does not have aws client installed so we are not able to use the aws s3 cp command in the job definition to copy the executable to the EC2 instance. getting following error,
CannotStartContainerError: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: &quot;aws&quot;: executable file not found in $PATH: unknown
  1. with the wget command, the executable gets downloaded to EC2 from the s3 bucket; but the bash command in the job definition, is not able to distinguish the next command. Say wget <source-url> && java -jar executable.jar -> here it tries to process wget on '&&', tried multiple ways to provide two commands in single bash line but did not work. Getting following errors,
    wget: unable to resolve host address java <- without using ampersand in bash of job definition
    wget: unable to resolve host address ‘&amp;&amp;’ <- with ampersand etc. separators for commands in bash

答案1

得分: 0

如果我理解你的情况正确,我相信你正在将命令wget <url> -O executable.jar && java -jar executable.jar 作为可执行命令传递。容器不会在shell中运行它,它只将其视为带有一组奇怪参数的单个命令。相反,你可以在shell中运行它,使用bash -c "wget <url> -O executable.jar && java -jar executable.jar"。如果你的容器中没有bash,你可能需要使用sh

关于AWS CLI,你应该能够在Amazon Linux中使用yum install awscli来安装它。我相信它会从容器中获取凭据,你可以在Batch中配置它以访问你的S3存储桶。

英文:

If I'm understanding your scenario right, I believe you're passing the command wget &lt;url&gt; -O executable.jar &amp;&amp; java -jar executable.jar as the executable command. The container doesn't run this in a shell; it just views it as a single command with a strange set of arguments. Instead you could run it in a shell with bash -c &quot;wget &lt;url&gt; -O executable.jar &amp;&amp; java -jar executable.jar&quot;. You might need to use sh if bash isn't available in your container.

Regarding the AWS CLI, you should be able to install it in Amazon Linux with yum install awscli. I believe it would pick up the credentials from your container, which you can configure in Batch to have access to your S3 bucket.

huangapple
  • 本文由 发表于 2023年3月1日 16:31:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定