

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

# 定义任务模板参数
<a name="use-job-template-parameters"></a>

借助任务模板参数，您可以在任务模板中指定变量。使用该任务模板启动任务运行时，您需要指定这些参数变量的值。任务模板参数以 `${parameterName}` 格式指定。您可以选择将 `jobTemplateData` 字段中的任何值指定为任务模板参数。指定每个任务模板参数变量的数据类型（`STRING` 或 `NUMBER`），此外还可以选择指定一个默认值。以下示例演示了如何为入口点位置、主类和 S3 日志位置值指定任务模板参数。

**将入口点位置、主类和 Amazon S3 日志位置指定为任务模板参数**

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

   ```
   {
      "name": "mytemplate",
      "jobTemplateData": {
           "executionRoleArn": "iam_role_arn_for_job_execution", 
           "releaseLabel": "emr-6.7.0-latest",
           "jobDriver": {
               "sparkSubmitJobDriver": { 
                   "entryPoint": "${EntryPointLocation}",
                   "entryPointArguments": [ "argument1","argument2",...],
                   "sparkSubmitParameters": "--class ${MainClass} --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": "${LogS3BucketUri}"
                   }
               }
           },
           "parameterConfiguration": {
               "EntryPointLocation": {
                   "type": "STRING"
               },
               "MainClass": {
                   "type": "STRING",
                   "defaultValue":"Main"
               },
               "LogS3BucketUri": {
                   "type": "STRING",
                   "defaultValue":"s3://my_s3_log_location/"
               }
           }
       }
   }
   ```

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

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

**使用具有任务模板参数的任务模板启动任务运行**

要使用包含任务模板参数的任务模板启动运行任务，请在 `StartJobRun` API 请求中指定任务模板 ID 以及任务模板参数的值，如下例所示。

```
aws emr-containers start-job-run \
--virtual-cluster-id 123456 \
--name myjob \
--job-template-id 1234abcd \
--job-template-parameters '{"EntryPointLocation": "entry_point_location","MainClass": "ExampleMainClass","LogS3BucketUri": "s3://example_s3_bucket/"}'
```