

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS Batch 事件
<a name="batch_cwe_events"></a>

AWS Batch 向。发送任务状态更改事件 EventBridge。 AWS Batch 跟踪您的工作状态。如果先前提交的作业的状态发生变化，则会调用一个事件。例如，如果状态为`RUNNING`的作业变为`FAILED`状态。这些事件归类为作业状态更改事件。

**注意**  
AWS Batch 将来可能会添加其他事件类型、来源和细节。如果以编程方式对事件 JSON 数据反序列化，请确保应用程序已准备好处理未知属性。这是为了避免在添加这些附加属性时出现问题。

# 作业状态更改事件
<a name="batch_job_events"></a>

只要现有 (以前提交的) 作业状态发生更改，就会创建一个事件。有关AWS Batch作业状态的更多信息，请参阅[任务状态](job_states.md)。

**注意**  
对于初始作业提交不会创建事件。

**Example 作业状态更改事件**  
作业状态更改事件以下面的形式传送。`detail` 部分类似于 *AWS BatchAPI Reference* 中的 [DescribeJobs](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeJobs.html) API 操作返回的[ JobDetail](https://docs.aws.amazon.com/batch/latest/APIReference/API_JobDetail.html) 对象。有关 EventBridge 参数更多信息，请参阅 *Amazon EventBridge 用户指南*中[事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)。  

```
{
    "version": "0",
    "id": "c8f9c4b5-76e5-d76a-f980-7011e206042b",
    "detail-type": "Batch Job State Change",
    "source": "aws.batch",
    "account": "123456789012",
    "time": "2022-01-11T23:36:40Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:batch:us-east-1:123456789012:job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8"
    ],
    "detail": {
        "jobArn": "arn:aws:batch:us-east-1:123456789012:job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
        "jobName": "event-test",
        "jobId": "4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
        "jobQueue": "arn:aws:batch:us-east-1:123456789012:job-queue/PexjEHappyPathCanary2JobQueue",
        "status": "RUNNABLE",
        "attempts": [],
        "createdAt": 1641944200058,
        "retryStrategy": {
            "attempts": 2,
            "evaluateOnExit": []
        },
        "dependsOn": [],
        "jobDefinition": "arn:aws:batch:us-east-1:123456789012:job-definition/first-run-job-definition:1",
        "parameters": {},
        "container": {
            "image": "137112412989.dkr.ecr.us-east-1.amazonaws.com/amazonlinux:latest",
            "command": [
                "sleep",
                "600"
            ],
            "volumes": [],
            "environment": [],
            "mountPoints": [],
            "ulimits": [],
            "networkInterfaces": [],
            "resourceRequirements": [
                {
                    "value": "2",
                    "type": "VCPU"
                }, {
                    "value": "256",
                    "type": "MEMORY"
                }
            ],
            "secrets": []
        },
        "propagateTags": false,
        "platformCapabilities": []
    }
}
```

# 作业队列阻塞事件
<a name="batch-job-queue-blocked-events"></a>

每当 AWS Batch 检测到处于该`RUNNABLE`状态的任务从而阻塞队列时，都会在 Amazon Events 中创建一个 CloudWatch 事件。有关支持的队列阻止原因的更多信息，请参阅 [作业在`RUNNABLE`状态卡住](job_stuck_in_runnable.md)。同样的原因也提供在 [https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeJobs.html](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeJobs.html) API 操作的 `statusReason` 字段中。

**Example 作业队列阻塞事件**  
作业队列阻塞事件的传输格式如下。该`detail`部分类似于《API *参考*》中从 [DescribeJobs](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeJobs.html)API 操作返回的[JobDetail](https://docs.aws.amazon.com/batch/latest/APIReference/API_JobDetail.html)AWS Batch 对象。有关 EventBridge 参数的更多信息，请参阅 *Amazon EventBridge 用户指南*中的[事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)。  

```
{
    "version": "0",
    "id": "c8f9c4b5-76e5-d76a-f980-7011e206042b",
    "detail-type": "Batch Job Queue Blocked",
    "source": "aws.batch",
    "account": "123456789012",
    "time": "2022-01-11T23:36:40Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:batch:us-east-1:123456789012:job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
        "arn:aws:batch:us-east-1:123456789012:job-queue/PexjEHappyPathCanary2JobQueue"
    ],
    "detail": {
        "jobArn": "arn:aws:batch:us-east-1:123456789012:job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
        "jobName": "event-test",
        "jobId": "4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
        "jobQueue": "arn:aws:batch:us-east-1:123456789012:job-queue/PexjEHappyPathCanary2JobQueue",
        "status": "RUNNABLE",
        "statusReason": "blocked-reason",
        "attempts": [],
        "createdAt": 1641944200058,
        "retryStrategy": {
            "attempts": 2,
            "evaluateOnExit": []
        },
        "dependsOn": [],
        "jobDefinition": "arn:aws:batch:us-east-1:123456789012:job-definition/first-run-job-definition:1",
        "parameters": {},
        "container": {
            "image": "137112412989.dkr.ecr.us-east-1.amazonaws.com/amazonlinux:latest",
            "command": [
                "sleep",
                "600"
            ],
            "volumes": [],
            "environment": [],
            "mountPoints": [],
            "ulimits": [],
            "networkInterfaces": [],
            "resourceRequirements": [
                {
                    "value": "2",
                    "type": "VCPU"
                }, {
                    "value": "256",
                    "type": "MEMORY"
                }
            ],
            "secrets": []
        },
        "propagateTags": false,
        "platformCapabilities": []
    }
}
```

# 服务作业状态更改事件
<a name="service-job-events"></a>

只要现有服务作业状态发生更改，就会创建一个事件。有关服务作业状态的更多信息，请参阅[将 AWS Batch 服务作业状态映射到 SageMaker AI 状态](service-job-status.md)。

**注意**  
对于初始作业提交不会创建事件。

**Example 服务作业状态更改事件**  
服务作业状态更改事件的传输格式如下。`detail` 部分与《AWS Batch API 参考》中 [DescribeServiceJob](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeServiceJob.html) API 操作返回的响应相同**。有关 EventBridge 参数更多信息，请参阅 *Amazon EventBridge 用户指南*中[事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)。  
`detail` 事件不包含 `tags` 和 `serviceRequestPayload` 字段。

```
{
  "version": "0",
  "id": "c8f9c4b5-76e5-d76a-f980-7011e206042b",
  "detail-type": "Batch Service Job State Change",
  "source": "aws.batch",
  "account": "123456789012",
  "time": "2022-01-11T23:36:40Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:batch:us-east-1:123456789012:service-job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8"
  ],
  "detail": {
    "attempts": [
      {
        "serviceResourceId": {
          "name": "TrainingJobArn",
          "value": "arn:aws:sagemaker:us-east-1:123456789012:training-job/AWSBatchmy-training-job88b610a69aa8380ca5b0a7aba3f81cb8"
        },
        "startedAt": 1641944300058,
        "stoppedAt": 1641944400058,
        "statusReason": "Received status from SageMaker: Training job completed"
      }
    ],
    "createdAt": 1641944200058,
    "jobArn": "arn:aws:batch:us-east-1:123456789012:service-job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
    "jobId": "0bb17543-ece6-4480-b1a7-a556d344746b",
    "jobName": "event-test",
    "jobQueue": "arn:aws:batch:us-east-1:123456789012:job-queue/HappyPathJobQueue",
    "latestAttempt": {
      "serviceResourceId": {
        "name": "TrainingJobArn",
        "value": "arn:aws:sagemaker:us-east-1:123456789012:training-job/AWSBatchmy-training-job88b610a69aa8380ca5b0a7aba3f81cb8"
      }
    },
    "serviceJobType": "SAGEMAKER_TRAINING",
    "startedAt": 1641944300058,
    "status": "SUCCEEDED",
    "statusReason": "Received status from SageMaker: Training job completed",
    "stoppedAt": 1641944400058,
    "timeoutConfig": {
      "attemptDurationSeconds": 60
    }
  }
}
```

# 服务作业队列阻塞事件
<a name="batch-service-job-queue-blocked-events"></a>

每当 AWS Batch 检测到队列被阻塞时，都会在 Amazon Events 中创建一个 CloudWatch 事件。队列阻塞的原因也会在 [https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeServiceJob.html](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeServiceJob.html) API 操作的 `statusReason` 字段中提供。

**Example 服务作业队列阻塞事件**  
服务作业队列阻塞事件的传输格式如下。该`detail`部分类似于《API *参考*》中从 [DescribeServiceJob](https://docs.aws.amazon.com/batch/latest/APIReference/API_DescribeServiceJob.html)API 操作返回的AWS Batch 响应。有关 EventBridge参数的更多信息，请参阅 *Amazon EventBridge 用户指南*中的[事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)。  
`detail` 事件不包含 `tags` 和 `serviceRequestPayload` 字段。

```
{
  "version": "0",
  "id": "c8f9c4b5-76e5-d76a-f980-7011e206042b",
  "detail-type": "Batch Service Job Queue Blocked",
  "source": "aws.batch",
  "account": "123456789012",
  "time": "2022-01-11T23:36:40Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:batch:us-east-1:123456789012:service-job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8"
  ],
  "detail": {
    "attempts": [],
    "createdAt": 1641944200058,
    "jobArn": "arn:aws:batch:us-east-1:123456789012:service-job/4c7599ae-0a82-49aa-ba5a-4727fcce14a8",
    "jobId": "6271dfdf-d8a7-41b1-a4d2-55a2224f5375",
    "jobName": "event-test",
    "jobQueue": "arn:aws:batch:us-east-1:123456789012:job-queue/HappyPathJobQueue",
    "serviceJobType": "SAGEMAKER_TRAINING",
    "status": "RUNNABLE",
    "statusReason": "blocked-reason",
    "timeoutConfig": {
      "attemptDurationSeconds": 60
    }
  }
}
```

# 服务作业抢占事件
<a name="batch-service-job-preemption-events"></a>

每当抢占序列开始或完成时，就会发布抢占事件。首次触发抢占以回收借用容量时，就会创建已启动事件。当抢占序列完成时，将创建一个已完成的事件，其中包含抢占尝试的摘要。

**Example Service Job 抢占已启动事件**  
服务作业抢占已启动事件按以下格式传送。有关 EventBridge 参数的更多信息，请参阅 *Amazon EventBridge 用户指南*中的[事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)。  

```
{
  "version": "0",
  "id": "1b4a511e-2737-226a-a1e7-fc97f1cd9681",
  "detail-type": "Batch Service Job Preemption Started",
  "source": "aws.batch",
  "account": "123456789012",
  "time": "2026-03-16T19:57:27Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:batch:us-east-1:123456789012:service-job/51f245a9-2995-4a53-bced-7b3c00028f84"
  ],
  "detail": {
    "statusReason": "PREEMPTION_IN_PROGRESS: Cross-share preemption triggered to reclaim borrowed capacity",
    "preemptedJobArn": "arn:aws:batch:us-east-1:123456789012:service-job/51f245a9-2995-4a53-bced-7b3c00028f84",
    "status": "RUNNING"
  }
}
```

**Example Service Job 抢占已完成事件**  
服务作业抢占已完成事件按以下格式传送。该`preemptionSummary`字段包含有关抢占尝试的详细信息，包括计数和最近的抢占尝试信息。  

```
{
  "version": "0",
  "id": "2b1c6151-c166-edf5-822c-211b3bfd46b2",
  "detail-type": "Batch Service Job Preemption Completed",
  "source": "aws.batch",
  "account": "123456789012",
  "time": "2026-03-16T19:57:47Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:batch:us-east-1:123456789012:service-job/51f245a9-2995-4a53-bced-7b3c00028f84"
  ],
  "detail": {
    "preemptedJobArn": "arn:aws:batch:us-east-1:123456789012:service-job/51f245a9-2995-4a53-bced-7b3c00028f84",
    "preemptionSummary": {
      "preemptedAttemptCount": 1,
      "recentPreemptedAttempts": [
        {
          "serviceResourceId": {
            "name": "TrainingJobArn",
            "value": "arn:aws:sagemaker:us-east-1:123456789012:training-job/AWSBatchqm-training-job9b2f08f911cf3dd794c1b3e72ae7ca5f"
          },
          "startedAt": 1773690923359,
          "stoppedAt": 1773691064669,
          "statusReason": "Cross-share preemption triggered to reclaim borrowed capacity"
        }
      ]
    },
    "status": "RUNNABLE"
  }
}
```