

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 中的服務任務承載 AWS Batch
<a name="service-job-payload"></a>

當您使用 [SubmitServiceJob](https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitServiceJob.html) 提交服務任務時，您會提供兩個定義任務的關鍵參數： `serviceJobType`和 `serviceRequestPayload`。
+ `serviceJobType` 指定要執行任務 AWS 的服務。對於 SageMaker Training 任務，此值為 `SAGEMAKER_TRAINING`。
+ `serviceRequestPayload` 是以 JSON 編碼的字串，其中包含通常直接傳送到目標服務的完整請求。對於 SageMaker Training 任務，此承載包含與 SageMaker AI [CreateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html) API 相同的參數。

如需所有可用參數及其說明的完整清單，請參閱 SageMaker AI [CreateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html) API 參考。支援的所有參數`CreateTrainingJob`都可以包含在服務任務承載中。

如需更多訓練任務組態的範例，請參閱 [SageMaker AI 開發人員指南](https://docs.aws.amazon.com/sagemaker/latest/dg/gs.html)中的 [APIs、CLI 和 SDKs](https://docs.aws.amazon.com/sagemaker/latest/dg/api-and-sdk-reference-overview.html)。

我們建議您使用 PySDK 建立服務任務，因為 PySDK 具有協助程式類別和公用程式。如需使用 PySDK 的範例，請參閱 GitHub 上的 [SageMaker AI 範例](https://github.com/aws/amazon-sagemaker-examples)。

## 服務任務承載範例
<a name="service-job-payload-example"></a>

下列範例顯示執行「hello world」訓練指令碼的 SageMaker 訓練任務的簡單服務任務承載：

呼叫 時，此承載會以 JSON 字串的形式傳遞給 `serviceRequestPayload` 參數`SubmitServiceJob`。

```
{
  "TrainingJobName": "my-simple-training-job",
  "RoleArn": "arn:aws:iam::123456789012:role/SageMakerExecutionRole",
  "AlgorithmSpecification": {
    "TrainingInputMode": "File",
    "TrainingImage": "763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:2.0.0-cpu-py310",
    "ContainerEntrypoint": [
      "echo",
      "hello world"
    ]
  },
  "ResourceConfig": {
    "InstanceType": "ml.c5.xlarge",
    "InstanceCount": 1,
    "VolumeSizeInGB": 1
  },
  "OutputDataConfig": {
    "S3OutputPath": "s3://your-output-bucket/output"
  },
  "StoppingCondition": {
    "MaxRuntimeInSeconds": 30
  }
}
```