0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWS】JobStateTimeLimitActionsReasonで「Invalid job reason」のエラーが出た場合

Posted at

概要

AWS Batchでは、RUNNABLE状態でスタックしたジョブを検出することができます。

こちらをAWS Cloudformationを使って構築しようと思ったら以下のエラーに。

Resource handler returned message: "Invalid job reason...

原因と解決方法を紹介します。

原因

ジョブキューは以下のように定義しました。

  BatchJobQueue:
    Type: 'AWS::Batch::JobQueue'
    Properties:
      ComputeEnvironmentOrder:
        - ComputeEnvironment: !Ref BatchComputeEnvironment
          Order: 1
      Priority: 1
      State: ENABLED
      JobStateTimeLimitActions:
        - State: RUNNABLE
          Reason: INSUFFICIENT_INSTANCE_CAPACITY
          MaxTimeSeconds: 600
          Action: CANCEL
        - State: RUNNABLE
          Reason: COMPUTE_ENVIRONMENT_MAX_RESOURCE
          MaxTimeSeconds: 600
          Action: CANCEL
        - State: RUNNABLE
          Reason: JOB_RESOURCE_REQUIREMENT
          MaxTimeSeconds: 600
          Action: CANCEL
      JobQueueName: sample-batch-job-queue

上記でInvalid job reasonが出た理由は何か?
それはReasonの値が適切ではなかったためです。

ちなみに上記のReasonは、CDKではそのように設定する、と記載があったためです。

ちなみに以下のAWS公式ドキュメントの方にはどんな値が設定できるかの記述はありませんでした。

解決方法

AWSマネジメントコンソールで手動でJobStateTimeLimitActionsパラメーターを設定してCLIを叩いてみると以下のように出てきました。

{
    "jobQueues": [
        {
            "jobQueueName": "sample-batch-job-queue",
            "jobQueueArn": "arn:aws:batch:ap-northeast-1:xxxxxxxxxx:job-queue/sample-batch-job-queue",
            "state": "ENABLED",
            "status": "VALID",
            "statusReason": "JobQueue Healthy",
            "priority": 1,
            "computeEnvironmentOrder": [
                {
                    "order": 1,
                    "computeEnvironment": "arn:aws:batch:ap-northeast-1:xxxxxxxxxx:compute-environment/sample-batch-ec2-compute-environment"
                }
            ],
            "tags": {},
            "jobStateTimeLimitActions": [
                {
                    "reason": "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE",
                    "state": "RUNNABLE",
                    "maxTimeSeconds": 600,
                    "action": "CANCEL"
                },
                {
                    "reason": "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT",
                    "state": "RUNNABLE",
                    "maxTimeSeconds": 600,
                    "action": "CANCEL"
                },
                {
                    "reason": "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY",
                    "state": "RUNNABLE",
                    "maxTimeSeconds": 600,
                    "action": "CANCEL"
                }
            ]
        }
    ]

あら、Reasonの値の頭にMISCONFIGURATIONとかついている!?

なるほど、CDKのENUMと値が違うのですね。。
ということでyamlw以下のように修正したらエラーが出なくなりました。

  BatchJobQueue:
    Type: 'AWS::Batch::JobQueue'
    Properties:
      ComputeEnvironmentOrder:
        - ComputeEnvironment: !Ref BatchComputeEnvironment
          Order: 1
      Priority: 1
      State: ENABLED
      JobStateTimeLimitActions:
        - State: RUNNABLE
          Reason: CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY
          MaxTimeSeconds: 600
          Action: CANCEL
        - State: RUNNABLE
          Reason: MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE
          MaxTimeSeconds: 600
          Action: CANCEL
        - State: RUNNABLE
          Reason: MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT
          MaxTimeSeconds: 600
          Action: CANCEL
      JobQueueName: sample-batch-job-queue

解決!

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?