# IoT Data

Source: /aws/services/iot-data/

## Introduction

IoT Data provides secure, bi-directional communication between Internet-connected things, such as sensors, actuators, embedded devices, or smart appliances, and the AWS Cloud.
It allows you to connect your devices to the cloud and interact with them using the AWS Management Console, AWS CLI, or AWS SDKs.

LocalStack allows you to use the IoT Data APIs to update, get, and delete the shadow of a thing in your local environment.
The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of IoT Data integration with LocalStack.

## Getting started

This guide is designed for users new to IoT Data and assumes basic knowledge of the AWS CLI and our [`lstk aws`](/aws/developer-tools/running-localstack/lstk/cloud-and-iac-commands/#aws) command.

Start your LocalStack container using your preferred method.
We will demonstrate how to create a thing, update its shadow, get its shadow, and delete its shadow using IoT Data.

### Update the shadow

You can update the shadow of a thing using the [`UpdateThingShadow`](https://docs.aws.amazon.com/iot/latest/apireference/API_UpdateThingShadow.html) API.
Run the following command to update the shadow of a thing named `MyRPi`:

```bash
lstk aws iot-data update-thing-shadow \
    --thing-name "MyRPi" \
    --payload "{\"state\":{\"reported\":{\"moisture\":\"okay\"}}}" \
    output.txt --cli-binary-format raw-in-base64-out
```

The `output.txt` file contains the following output:

```text title="output.txt"
{
    "state": {
        "reported": {
            "moisture": "okay"
        }
    },
    "metadata": {
        "reported": {
            "moisture": {
                "timestamp": 1724226109
            }
        }
    },
    "version": 1,
    "timestamp": 1724226109
}
```

### Get the shadow

You can get the shadow of a thing using the [`GetThingShadow`](https://docs.aws.amazon.com/iot/latest/apireference/API_GetThingShadow.html) API.
Run the following command to get the shadow:

```bash
lstk aws iot-data get-thing-shadow \
    --thing-name "MyRPi" \
    output.txt
```

The `output.txt` will contain the same output as the previous command.

### Delete the shadow

You can delete the shadow of a thing using the [`DeleteThingShadow`](https://docs.aws.amazon.com/iot/latest/apireference/API_DeleteThingShadow.html) API.
Run the following command to delete the shadow:

```bash
lstk aws iot-data delete-thing-shadow \
    --thing-name "MyRPi" \
    output.txt
```

The `output.txt` will contain the following output:

```text title="output.txt"
{
    "version": 1,
    "timestamp": 1724226371
}
```

## Device Shadows

LocalStack supports both unnamed (classic) and named device shadows.

You can use AWS CLI and [MQTT topics](https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html) to get, update or delete device shadow state information.

The endpoint as returned by `DescribeEndpoint` currently does not support the [device shadow REST API](https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-rest-api.html#API_GetThingShadow)

## API Coverage


### IoT Data API coverage

Source service: `iot-data`. 5 of 11 tracked operations are implemented.

Service documentation: /aws/services/iot-data/
License availability: available starting with the Ultimate plan. See /aws/licensing/ for current plan details.

| Operation | Status |
| --- | --- |
| DeleteConnection | Not implemented |
| DeleteThingShadow | Implemented |
| GetConnection | Not implemented |
| GetRetainedMessage | Not implemented |
| GetThingShadow | Implemented |
| ListNamedShadowsForThing | Implemented |
| ListRetainedMessages | Not implemented |
| ListSubscriptions | Not implemented |
| Publish | Implemented |
| SendDirectMessage | Not implemented |
| UpdateThingShadow | Implemented |
