

**This documentation is for Version 1 of the Amazon CLI only.**

We announced the upcoming end-of-support for the Amazon CLI version 1. We recommend that you migrate to the Amazon CLI version 2. For dates, additional details, and information on how to migrate, see the [announcement](https://amazonaws-china.com/blogs/developer/cli-v1-maintenance-mode-announcement/). For documentation related to Version 2 of the Amazon CLI, see the [Version 2 User Guide](https://docs.amazonaws.cn/cli/latest/userguide/).

# Amazon IoT Jobs SDK release examples using Amazon CLI
<a name="cli_iot-jobs-data-plane_code_examples"></a>

The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon IoT Jobs SDK release.

*Actions* are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

**Topics**
+ [Actions](#actions)

## Actions
<a name="actions"></a>

### `describe-job-execution`
<a name="iot-jobs-data-plane_DescribeJobExecution_cli_topic"></a>

The following code example shows how to use `describe-job-execution`.

**Amazon CLI**  
**To get the details of a job execution**  
The following `describe-job-execution` example retrieves the details of the latest execution of the specified job and thing.  

```
aws iot-jobs-data describe-job-execution \
    --job-id {{SampleJob}} \
    --thing-name {{MotionSensor1}} \
    --endpoint-url {{https://1234567890abcd.jobs.iot.us-west-2.amazonaws.com}}
```
Output:  

```
{
    "execution": {
        "approximateSecondsBeforeTimedOut": 88,
        "executionNumber": 2939653338,
        "jobId": "SampleJob",
        "lastUpdatedAt": 1567701875.743,
        "queuedAt": 1567701902.444,
        "status": "QUEUED",
        "thingName": "MotionSensor1 ",
        "versionNumber": 3
   }
}
```
For more information, see [Devices and Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/jobs-devices.html) in the *Amazon IoT Developer Guide*.  
+  For API details, see [DescribeJobExecution](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-jobs-data/describe-job-execution.html) in *Amazon CLI Command Reference*. 

### `get-pending-job-executions`
<a name="iot-jobs-data-plane_GetPendingJobExecutions_cli_topic"></a>

The following code example shows how to use `get-pending-job-executions`.

**Amazon CLI**  
**To get a list of all jobs that are not in a terminal status for a thing**  
The following `get-pending-job-executions` example displays a list of all jobs that aren't in a terminal state for the specified thing.  

```
aws iot-jobs-data get-pending-job-executions \
    --thing-name {{MotionSensor1}}
    --endpoint-url {{https://1234567890abcd.jobs.iot.us-west-2.amazonaws.com}}
```
Output:  

```
{
    "inProgressJobs": [
    ],
    "queuedJobs": [
        {
            "executionNumber": 2939653338,
            "jobId": "SampleJob",
            "lastUpdatedAt": 1567701875.743,
            "queuedAt": 1567701902.444,
            "versionNumber": 3
      }
    ]
}
```
For more information, see [Devices and Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/jobs-devices.html) in the *Amazon IoT Developer Guide*.  
+  For API details, see [GetPendingJobExecutions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-jobs-data/get-pending-job-executions.html) in *Amazon CLI Command Reference*. 

### `start-next-pending-job-execution`
<a name="iot-jobs-data-plane_StartNextPendingJobExecution_cli_topic"></a>

The following code example shows how to use `start-next-pending-job-execution`.

**Amazon CLI**  
**To get and start the next pending job execution for a thing**  
The following `start-next-pending-job-execution` example retrieves and starts the next job execution whose status is IN\_PROGRESS or QUEUED for the specified thing.  

```
aws iot-jobs-data start-next-pending-job-execution \
    --thing-name {{MotionSensor1}}
    --endpoint-url {{https://1234567890abcd.jobs.iot.us-west-2.amazonaws.com}}
```
Output:  

```
{
    "execution": {
        "approximateSecondsBeforeTimedOut": 88,
        "executionNumber": 2939653338,
        "jobId": "SampleJob",
        "lastUpdatedAt": 1567714853.743,
        "queuedAt": 1567701902.444,
        "startedAt": 1567714871.690,
        "status": "IN_PROGRESS",
        "thingName": "MotionSensor1 ",
        "versionNumber": 3
   }
}
```
For more information, see [Devices and Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/jobs-devices.html) in the *Amazon IoT Developer Guide*.  
+  For API details, see [StartNextPendingJobExecution](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-jobs-data/start-next-pending-job-execution.html) in *Amazon CLI Command Reference*. 

### `update-job-execution`
<a name="iot-jobs-data-plane_UpdateJobExecution_cli_topic"></a>

The following code example shows how to use `update-job-execution`.

**Amazon CLI**  
**To update the status of a job execution**  
The following `update-job-execution` example updates the status of the specified job and thing.  

```
aws iot-jobs-data update-job-execution \
    --job-id {{SampleJob}} \
    --thing-name {{MotionSensor1}} \
    --status {{REMOVED}} \
    --endpoint-url {{https://1234567890abcd.jobs.iot.us-west-2.amazonaws.com}}
```
Output:  

```
{
    "executionState": {
        "status": "REMOVED",
        "versionNumber": 3
    },
}
```
For more information, see [Devices and Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/jobs-devices.html) in the *Amazon IoT Developer Guide*.  
+  For API details, see [UpdateJobExecution](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-jobs-data/update-job-execution.html) in *Amazon CLI Command Reference*. 