

**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 data examples using Amazon CLI
Amazon IoT data

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

*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
Actions

### `delete-thing-shadow`
`delete-thing-shadow`

The following code example shows how to use `delete-thing-shadow`.

**Amazon CLI**  
**To delete a device's shadow document**  
The following `delete-thing-shadow` example deletes the entire shadow document for the device named `MyRPi`.  

```
aws iot-data delete-thing-shadow \
    --thing-name MyRPi \
    "output.txt"
```
The command produces no output on the display, but `output.txt` contains information that confirms the version and timestamp of the shadow document that you deleted.  

```
{"version":2,"timestamp":1560270384}
```
For more information, see [Using Shadows](https://docs.aws.amazon.com/iot/latest/developerguide/using-device-shadows.html) in the *Amazon IoT Developers Guide*.  
+  For API details, see [DeleteThingShadow](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-data/delete-thing-shadow.html) in *Amazon CLI Command Reference*. 

### `get-thing-shadow`
`get-thing-shadow`

The following code example shows how to use `get-thing-shadow`.

**Amazon CLI**  
**To get a thing shadow document**  
The following `get-thing-shadow` example gets the thing shadow document for the specified IoT thing.  

```
aws iot-data get-thing-shadow \
    --thing-name MyRPi \
    output.txt
```
The command produces no output on the display, but the following shows the contents of `output.txt`:  

```
{
  "state":{
    "reported":{
    "moisture":"low"
    }
  },
  "metadata":{
    "reported":{
      "moisture":{
        "timestamp":1560269319
      }
    }
  },
  "version":1,"timestamp":1560269405
}
```
For more information, see [Device Shadow Service Data Flow](https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-data-flow.html) in the *Amazon IoT Developers Guide*.  
+  For API details, see [GetThingShadow](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-data/get-thing-shadow.html) in *Amazon CLI Command Reference*. 

### `update-thing-shadow`
`update-thing-shadow`

The following code example shows how to use `update-thing-shadow`.

**Amazon CLI**  
**To update a thing shadow**  
The following `update-thing-shadow` example modifies the current state of the device shadow for the specified thing and saves it to the file `output.txt`.  

```
aws iot-data update-thing-shadow \
    --thing-name MyRPi \
    --payload "{"state":{"reported":{"moisture":"okay"}}}" \
    "output.txt"
```
The command produces no output on the display, but the following shows the contents of `output.txt`:  

```
{
    "state": {
        "reported": {
            "moisture": "okay"
        }
    },
    "metadata": {
        "reported": {
            "moisture": {
                "timestamp": 1560270036
            }
        }
    },
    "version": 2,
    "timestamp": 1560270036
}
```
For more information, see [Device Shadow Service Data Flow](https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-data-flow.html) in the *Amazon IoT Developers Guide*.  
+  For API details, see [UpdateThingShadow](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot-data/update-thing-shadow.html) in *Amazon CLI Command Reference*. 