

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

# 创建并使用作业模板启动作业运行
<a name="create-job-template"></a>

本节介绍如何创建作业模板以及使用模板通过 Amazon Command Line Interface (Amazon CLI) 开始作业运行。

**创建任务模板**

1. 创建一个 `create-job-template-request.json` 文件并指定任务模板所需的参数，如下面的示例 JSON 文件所示。有关所有可用参数的信息，请参阅 [CreateJobTemplate](https://docs.amazonaws.cn/emr-on-eks/latest/APIReference/Welcome.html)API。

   `StartJobRun` API 所需的大多数值也是 `jobTemplateData` 所必需的。如果您想为任何参数使用占位符并在 StartJobRun 使用作业模板调用时提供值，请参阅下一节有关作业模板参数的内容。

   ```
   {
      "name": "{{mytemplate}}",
      "jobTemplateData": {
           "executionRoleArn": "{{iam_role_arn_for_job_execution}}", 
           "releaseLabel": "emr-6.7.0-latest",
           "jobDriver": {
               "sparkSubmitJobDriver": { 
                   "entryPoint": "{{entryPoint_location}}",
                   "entryPointArguments": [ "{{argument1}}","{{argument2}}",...],
                   "sparkSubmitParameters": "--class <{{main_class}}> --conf spark.executor.instances=2 --conf spark.executor.memory=2G --conf spark.executor.cores=2 --conf spark.driver.cores=1"
               }
           },
           "configurationOverrides": {
               "applicationConfiguration": [
                   {
                       "classification": "spark-defaults", 
                       "properties": {
                            "spark.driver.memory":"2G"
                       }
                   }
               ], 
               "monitoringConfiguration": {
                   "persistentAppUI": "ENABLED", 
                   "cloudWatchMonitoringConfiguration": {
                       "logGroupName": "{{my_log_group}}", 
                       "logStreamNamePrefix": "{{log_stream_prefix}}"
                   }, 
                   "s3MonitoringConfiguration": {
                       "logUri": "s3://{{my_s3_log_location}}/"
                   }
               }
           }
        }
   }
   ```

1. 使用 `create-job-template` 命令和存储在本地的 `create-job-template-request.json` 文件路径。

   ```
   aws emr-containers create-job-template \ 
   --cli-input-json file:{{//./create-job-template-request.json}}
   ```

**使用任务模板启动任务运行**

在 `StartJobRun` 命令中提供虚拟集群 ID、任务模板 ID 和任务名称，如以下示例所示。

```
aws emr-containers start-job-run \
--virtual-cluster-id {{123456}} \
--name {{myjob}} \
--job-template-id {{1234abcd}}
```