[Yandex Cloud documentation](../../index.md) > [Yandex IoT Core](../index.md) > [Step-by-step guides](index.md) > Exporting messages to Data Streams

# Exporting messages to Data Streams

{% note warning %}

Yandex IoT Core is no longer available to new users. 

Current users can create resources until November 1, 2026. Afterwards, the service will go read-only and cease to operate on December 1, 2026. For more information on the timing and procedure, see [Service shutdown](../sunset.md).

{% endnote %}

{% note info %}

You can export data to [Data Streams](../../data-streams/index.md) only from the `*/events` and `*/commands` topics.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where the registry is located.
  1. Navigate to **IoT Core**.
  1. Select the required registry from the list.
  1. Navigate to the **Export to Data Streams** tab.
  1. In the top-right corner, click **Add export**.
  1. Fill out the fields as follows:

     * **Name**: Export name.
     * **MQTT topic filter**: Specify the topic from which you want to export messages or a filter using [wildcard characters](../concepts/topic/usage.md#wildcards). If you leave this field empty, messages will be exported from all topics within the registry, including topics from all devices within the registry.
     * **Data stream**: Specify the name of the [data stream](../../data-streams/concepts/glossary.md#stream-concepts) where you want to send messages from MQTT topics, or [create a new one](../../data-streams/operations/manage-streams.md#create-data-stream). If you chose to create a new stream, click **Update** to update the list of streams.
     * **Service account**: Specify a [service account](../../iam/concepts/users/service-accounts.md) with the `yds.writer` role.

  1. Click **Add**.

- CLI {#cli}
  
  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
  
  To create an export:

  1. Get a list of registries in the folder:

     ```bash
     yc iot registry list
     ```

     Result:

     ```text
     +----------------------+-------------------+
     |          ID          |       NAME        |
     +----------------------+-------------------+
     | arenou2oj4********** | my-registry       |
     +----------------------+-------------------+
     ```

  1. Create an export:

     ```bash
     yc iot registry yds-export add \
       --registry-name <registry_name> \
       --name <export_name> \
       --database <DB_path> \
       --stream <stream_name> \
       --mqtt-topic-filter <topic> \
       --stream-service-account-name <service_account_name>
     ```

     Where:

     * `--registry-name`: Registry name.
     * `--name`: Export name.
     * `--database`: [Location of the database](https://ydb.tech/docs/en//concepts/connect#database) storing the stream data, the second part of the **Endpoint** field value (following `/?database=`), e.g., `/ru-central1/r1gra875baom********/g5n22e7ejf**********`.
     * `--stream`: Name of the [data stream](../../data-streams/concepts/glossary.md#stream-concepts) to receive messages from MQTT topics.
     * `--mqtt-topic-filter`: Topic to export messages from or filter using [wildcard characters](../concepts/topic/usage.md#wildcards). If this parameter is not specified, messages will be exported from all topics within the registry, including topics from all devices within the registry.
     * `--stream-service-account-name`: Name of the [service account](../../iam/concepts/users/service-accounts.md) with the `yds.writer` role.

     Result:

     ```text
     id: are520n46t**********
     name: export-from-topic
     registry_id: areqqa5ntm**********
     database: /ru-central1/b1gia87mbaom********/etnu4r0v1c**********
     stream: topic-message-stream
     service_account_id: ajeu9klp40**********
     created_at: "2023-09-18T09:52:28.840124837Z"
     ```

- API {#api}

  To add the export to Data Streams for a registry, use the [RegistryService/AddDataStreamExport](../api-ref/grpc/Registry/addDataStreamExport.md) gRPC API call.

{% endlist %}

## Useful links {#see-also}

* [Exporting to Data Streams](../concepts/topic/usage.md#yds-export)