症状
-
AWS Batch > ジョブ > 詳細
を確認すると、結果がFailedになっていた - 同ページ内の、
コンテナ
と書かれたカードの理由欄に以下のようなエラーが吐き出されていた。
CannotStartContainerError: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"which python\": executable file not found in $PATH": unknown
AWS Batch > ジョブ > 詳細
ページは以下のような感じになっている。
&& ls
は気にしないで...debugしたかったの...。
原因
原因は簡単で、serverless frameworkのCommand
の記載方法が間違っていた。
serverless.ymlの一部
Resources:
TrialJobDefinition:
Type: AWS::Batch::JobDefinition
Properties:
JobDefinitionName: ${self:custom.job_definition_name}
Type: container
ContainerProperties:
Image: !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${self:custom.image_name}:latest'
Memory: 512
Vcpus: 1
Command:
- python main.py # <--- ダメ
対策
Command
部分を以下のように直したところ、正常に動作した。
serverless.ymlの一部
Resources:
TrialJobDefinition:
Type: AWS::Batch::JobDefinition
Properties:
JobDefinitionName: ${self:custom.job_definition_name}
Type: container
ContainerProperties:
Image: !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${self:custom.image_name}:latest'
Memory: 512
Vcpus: 1
Command: ["python", "main.py"] # <--- OK
DockerfileのCMD
と同じ書き方をしないといけないらしい。