

# Create custom job templates
<a name="job-templates-create"></a>

You can create job templates by using the Amazon CLI and the Amazon IoT console. You can also create jobs from job templates by using the Amazon CLI, the Amazon IoT console, and Fleet Hub for Amazon IoT Device Management web applications. For more information about working with job templates in Fleet Hub applications, see [Working with job templates in Fleet Hub for Amazon IoT Device Management](https://docs.amazonaws.cn/iot/latest/fleethubuserguide/aws-iot-monitor-technician-job-templates.html).

**Note**  
The total number of substitution patterns in a job document should be less than or equal to ten.

**Topics**
+ [

# Create custom job templates by using the Amazon Web Services Management Console
](job-templates-console.md)
+ [

# Create custom job templates by using the Amazon CLI
](job-templates-cli.md)

# Create custom job templates by using the Amazon Web Services Management Console
<a name="job-templates-console"></a>

This topic explains how to create, delete, and view details about job templates by using the Amazon IoT console.

## Create a custom job template
<a name="job-templates-console-create"></a>

You can either create an original custom job template or create a job template from an existing job. You can also create a custom job template from an existing job that was created using an Amazon managed template. For more information, see [Create custom job templates from managed templates](job-template-manage-console-create.md#job-template-manage-create-template).

### Create an original job template
<a name="job-templates-console-create-scratch"></a>

1. 

**Start creating your job template**

   1. Go to the [Job templates hub of the Amazon IoT console](https://console.amazonaws.cn/iot/home#/jobtemplatehub) and choose the **Custom templates** tab.

   1. Choose **Create job template**.
**Note**  
You can also navigate to the **Job templates** page from the **Related services** page under **Fleet Hub**.

1. 

**Specify job template properties**

   In the **Create job template** page, enter an alphanumeric identifier for your job name and an alphanumeric description to provide additional details about the template.
**Note**  
We don't recommend using personally identifiable information in your job IDs or descriptions.

1. 

**Provide job document**

   Provide a JSON job file that is either stored in an S3 bucket or as an inline job document that is specified within the job. This job file will become the job document when you create a job using this template.

   If the job file is stored in an S3 bucket, enter the S3 URL or choose **Browse S3**, and then navigate to your job document and select it.
**Note**  
You can select only S3 buckets in your current Region.

1. Continue to add any additional configurations for your job and then review and create your job. For information about the additional, optional configurations, refer to the following links:
   + [Job rollout, scheduling, and abort configurations](jobs-configurations-details.md#job-rollout-abort-scheduling)
   + [Job execution timeout and retry configurations](jobs-configurations-details.md#job-timeout-retry)

### Create a job template from an existing job
<a name="job-templates-console-create-exist-job"></a>

1. 

**Choose your job**

   1. Go to the [Job hub of the Amazon IoT console](https://console.amazonaws.cn/iot/home#/jobhub) and choose the job that you want to use as the basis for your job template.

   1. Choose **Save as a job template**.
**Note**  
Optionally, you can choose a different job document or edit the advanced configurations from the original job, and then choose **Create job template**. Your new job template appears on the **Job templates** page.

1. 

**Specify job template properties**

   In the **Create job template** page, enter an alphanumeric identifier for your job name and an alphanumeric description to provide additional details about the template.
**Note**  
The job document is the job file that you specified when creating the template. If the job document is specified within the job instead of an S3 location, you can see the job document in the details page of this job.

1. Continue to add any additional configurations for your job and then review and create your job. For information about the additional configurations, see:
   + [Job rollout, scheduling, and abort configurations](jobs-configurations-details.md#job-rollout-abort-scheduling)
   + [Job execution timeout and retry configurations](jobs-configurations-details.md#job-timeout-retry)

## Create a job from a custom job template
<a name="job-templates-console-create-job-from"></a>

You can create a job from a custom job template by going to the details page of your job template as described in this topic. You can also create a job or by choosing the job template you want to use when running the job creation workflow. For more information, see [Create and manage jobs by using the Amazon Web Services Management Console](manage-job-console.md).

This topic shows how to create a job from the details page of a custom job template. You can also create a job from an Amazon managed template. For more information, see [Create a job using managed templates](job-template-manage-console-create.md#job-template-manage-create-job).

1. 

**Choose your custom job template**

   Go to the [Job templates hub of the Amazon IoT console](https://console.amazonaws.cn/iot/home#/jobtemplatehub) and choose the **Custom templates** tab, and then choose your template.

1. 

**Create a job using your custom template**

   To create a job:

   1. In the details page of your template, choose **Create job**.

      The console switches to the **Custom job properties** step of the **Create job** workflow where your template configuration has been added.

   1. Enter a unique alphanumeric job name, and optional description and tags, and then choose **Next**.

   1. Choose the things or thing groups as job targets that you want to run in this job.

      In the **Job document** section, your template is displayed with its configuration settings. If you want to use a different job document, choose **Browse** and select a different bucket and document. Choose **Next**.

   1. On the **Job configuration** page, choose the job type as continuous or a snapshot job. A snapshot job is complete when it finishes its run on the target devices and groups. A continuous job applies to thing groups and runs on any device that you add to a specified target group.

   1. Continue to add any additional configurations for your job and then review and create your job. For information about the additional configurations, see:
      + [Job rollout, scheduling, and abort configurations](jobs-configurations-details.md#job-rollout-abort-scheduling)
      + [Job execution timeout and retry configurations](jobs-configurations-details.md#job-timeout-retry)

**Note**  
When a job created from a job template updates the existing parameters provided by the job template, those updated parameters will override the existing parameters provided by the job template for that job.

You can also create jobs from job templates with Fleet Hub web applications. For information about creating jobs in Fleet Hub, see [Working with job templates in Fleet Hub for Amazon IoT Device Management](https://docs.amazonaws.cn/iot/latest/fleethubuserguide/aws-iot-monitor-technician-job-templates.html).

## Delete a job template
<a name="job-templates-console-delete-job"></a>

To delete a job template, first go to the [Job templates hub of the Amazon IoT console](https://console.amazonaws.cn/iot/home#/jobtemplatehub) and choose the **Custom templates** tab. Then, choose the job template you want to delete and choose **Next**.

**Note**  
A deletion is permanent and the job template no longer appears on the **Custom templates** tab.

# Create custom job templates by using the Amazon CLI
<a name="job-templates-cli"></a>

This topic explains how to create, delete, and retrieve details about job templates by using the Amazon CLI.

## Create a job template from scratch
<a name="job-templates-cli-create-scratch"></a>

The following Amazon CLI command shows how to create a job using a job document (*job-document.json*) stored in an S3 bucket and a role with permission to download files from Amazon S3 (*S3DownloadRole*).

```
aws iot create-job-template  \
      --job-template-id 010  \
      --description "My custom job template for updating the device firmware"
      --document-source https://s3.amazonaws.com/amzn-s3-demo-bucket/job-document.json  \
      --timeout-config inProgressTimeoutInMinutes=100 \
      --job-executions-rollout-config "{ \"exponentialRate\": { \"baseRatePerMinute\": 50, \"incrementFactor\": 2, \"rateIncreaseCriteria\": { \"numberOfNotifiedThings\": 1000, \"numberOfSucceededThings\": 1000}}, \"maximumPerMinute\": 1000}" \
      --abort-config "{ \"criteriaList\": [ { \"action\": \"CANCEL\", \"failureType\": \"FAILED\", \"minNumberOfExecutedThings\": 100, \"thresholdPercentage\": 20}, { \"action\": \"CANCEL\", \"failureType\": \"TIMED_OUT\", \"minNumberOfExecutedThings\": 200, \"thresholdPercentage\": 50}]}" \          
      --presigned-url-config "{\"roleArn\":\"arn:aws:iam::123456789012:role/S3DownloadRole\", \"expiresInSec\":3600}"
```

The optional `timeout-config` parameter specifies the amount of time each device has to finish running the job. The timer starts when the job execution status is set to `IN_PROGRESS`. If the job execution status isn't set to another terminal state before the time expires, it's set to `TIMED_OUT`.

The in-progress timer can't be updated and applies to all job launches for the job. Whenever a job launch remains in the `IN_PROGRESS` state for longer than this interval, the job launch fails and switches to the terminal `TIMED_OUT` status. Amazon IoT also publishes an MQTT notification.

For more information about creating configurations about job rollouts and aborts, see [Job rollout and abort configuration](job-rollout-abort-scheduling.html).

**Note**  
Job documents that are specified as Amazon S3 files are retrieved at the time you create the job. If you change the contents of the Amazon S3 file you used as the source of your job document after you create the job, what is sent to the targets of the job doesn't change.

## Create a job template from an existing job
<a name="job-templates-cli-create-from-job"></a>

The following Amazon CLI command creates a job template by specifying the Amazon Resource Name (ARN) of an existing job. The new job template uses all of the configurations specified in the job. Optionally, you can change any of the configurations in the existing job by using any of the optional parameters.

```
aws iot create-job-template  \
      --job-arn arn:aws:iot:region:123456789012:job/job-name  \      
      --timeout-config inProgressTimeoutInMinutes=100
```

## Get details about a job template
<a name="job-templates-cli-describe"></a>

The following Amazon CLI command gets details about a specified job template.

```
aws iot describe-job-template \
      --job-template-id template-id
```

The command displays the following output.

```
{
   "abortConfig": { 
      "criteriaList": [ 
         { 
            "action": "string",
            "failureType": "string",
            "minNumberOfExecutedThings": number,
            "thresholdPercentage": number
         }
      ]
   },
   "createdAt": number,
   "description": "string",
   "document": "string",
   "documentSource": "string",
   "jobExecutionsRolloutConfig": { 
      "exponentialRate": { 
         "baseRatePerMinute": number,
         "incrementFactor": number,
         "rateIncreaseCriteria": { 
            "numberOfNotifiedThings": number,
            "numberOfSucceededThings": number
         }
      },
      "maximumPerMinute": number
   },
   "jobTemplateArn": "string",
   "jobTemplateId": "string",
   "presignedUrlConfig": { 
      "expiresInSec": number,
      "roleArn": "string"
   },
   "timeoutConfig": { 
      "inProgressTimeoutInMinutes": number
   }
}
```

## List job templates
<a name="job-templates-cli-list"></a>

The following Amazon CLI command lists all of the job templates in your Amazon Web Services account.

```
 aws iot list-job-templates
```

The command displays the following output.

```
{
   "jobTemplates": [ 
      { 
         "createdAt": number,
         "description": "string",
         "jobTemplateArn": "string",
         "jobTemplateId": "string"
      }
   ],
   "nextToken": "string"
}
```

To retrieve additional pages of results, use the value of the `nextToken` field.

## Delete a job template
<a name="job-templates-cli-delete"></a>

The following Amazon CLI command deletes a specified job template.

```
aws iot delete-job-template \
      --job-template-id template-id
```

The command displays no output.

## Create a job from a custom job template
<a name="job-templates-cli-create-job"></a>

The following Amazon CLI command creates a job from a custom job template. It targets a device named `thingOne` and specifies the Amazon Resource Name (ARN) of the job template to use as the basis for the job. You can override advanced configurations, such as timeout and cancel configurations, by passing the associated parameters of the `create-job` command.

**Warning**  
The `document-parameters` object must be used with the `create-job` command only when creating jobs from Amazon managed templates. This object must not be used with custom job templates. For an example that shows how to create jobs using this parameter, see [Create a job by using managed templates](job-template-manage-cli-create.md#job-template-manage-cli-create-job).

```
aws iot create-job \ 
      --targets arn:aws:iot:region:123456789012:thing/thingOne  \
      --job-template-arn arn:aws:iot:region:123456789012:jobtemplate/template-id
```