[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for YDB](../index.md) > [Tutorials](index.md) > Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them using Yandex DataLens

# Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them using Yandex DataLens


In this tutorial, you will set up streaming of [Yandex Cloud Postbox](../../postbox/index.md) events to [Yandex Data Streams](../../data-streams/index.md) and their visualization in [Yandex DataLens](../../datalens/index.md) for further analysis. Sending emails generates events.

You can implement this solution using the Yandex Cloud [management console](https://console.yandex.cloud) even if you have no coding skills. To process and store data, you will use [Yandex Cloud Functions](../../functions/index.md) and [Yandex Managed Service for YDB](../index.md).

To set up event streaming and visualization:

1. [Get your cloud ready](#before-begin).
1. [Create service accounts](#service-accounts).
1. [Create a static access key](#static-key).
1. [Configure your Managed Service for YDB database](#ydb).
1. [Create a data stream in Data Streams](#stream).
1. [Set up Yandex Cloud Postbox resources](#postbox).
1. [Set up Cloud Functions resources](#serverless-functions).
1. [Send emails](#send-letters).
1. [Configure visualization in DataLens](#datalens).

If you no longer need the resources you created, [delete them](#clear-out).


## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).


### Required paid resources {#paid-resources}

The infrastructure support cost includes:

* Fee for YDB operations and data storage (see [Yandex Managed Service for YDB pricing](../pricing/serverless.md)).
* Fee for Data Streams data storage (see [Yandex Data Streams pricing](../../data-streams/pricing.md)).
* Fee for function invocation count, computing resources allocated for the function, and outgoing traffic (see [Cloud Functions pricing](../../functions/pricing.md)).
* Fee for using Yandex Cloud Postbox (see [Yandex Cloud Postbox pricing](../../postbox/pricing.md)).
* Fee for the DataLens plan (see [Yandex DataLens pricing](../../datalens/pricing.md)).


## Create service accounts {#service-accounts}

Create these two [service accounts](../../iam/concepts/users/service-accounts.md):

* `yds-functions` to invoke the function from [Cloud Functions](../../functions/concepts/function.md) and write data to the YDB [database](../concepts/resources.md#database).
* `postbox-user` to send emails via Yandex Cloud Postbox.

1. Create a service account named `yds-functions`:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) where you are going to create your infrastructure.
      1. Navigate to **Identity and Access Management** and click **Create service account**.
      1. In the **Name** field, enter `yds-functions` for name.
      1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the `yds.editor` and `functions.functionInvoker` [roles](../../iam/concepts/access-control/roles.md).
      1. Click **Create**.

    {% endlist %}

1. Similarly, create a service account named `postbox-user` and assign the `postbox.sender` [role](../../postbox/security/index.md#postbox-sender) to it.

## Create a static access key {#static-key}

Create a [static access key](../../iam/concepts/authorization/access-key.md) to use for sending emails:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Identity and Access Management** and select `postbox-user` from the list of service accounts. In the window that opens:

      1. In the top panel, click ![plus](../../_assets/console-icons/plus.svg) **Create new key** and select **Create static access key**.
      1. Click **Create**.
      1. Save the ID and the secret key.

          {% note alert %}

          After you close this dialog, the key value will no longer be available.

          {% endnote %}

{% endlist %}


## Configure your Managed Service for YDB database {#ydb}

You can use any DBMS suitable for analytical tasks as an event storage. In this tutorial, we will use a Managed Service for YDB [serverless database](../concepts/resources.md#serverless). For other DBMS’s, the SQL query for creating a table and code for loading events into that table may be different.


### Create a database {#create-db}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Managed Service for&nbsp;YDB** and click **Create a database**.
  1. In the **Name** field, specify `postbox-events-ydb`.
  1. In the **Database type** field, select `Serverless`.
  1. Do not edit the other database settings. Click **Create a database**.

  Wait for the database to start. While being created, your database will have the `Provisioning` status. Once it is ready for use, its status will change to `Running`.

{% endlist %}


### Create a table {#create-table}

{% list tabs group=instructions %}

- Management console {#console}

  1. On the **Databases** page, select the new `postbox-events-ydb` database.
  1. To open the database root directory, navigate to the ![image](../../_assets/console-icons/folder.svg) **Navigation** tab.
  1. To query your database, click **New SQL query** in the top-right corner.
  1. In the **Query** box that opens, enter the following:

      ```sql
      CREATE TABLE postbox_events
      (
          saved_datetime Datetime NOT NULL,
          eventid String NOT NULL,
          eventtype String,
          mail_timestamp Timestamp,
          mail_messageid String,
          mail_ch_from String,
          mail_ch_to String, 
          mail_ch_messageid String,
          mail_ch_subject String,
          delivery_timestamp Timestamp,
          delivery_time_ms Uint64,
          delivery_recipients String,
          bounce_bounceType String,
          bounce_bounceSubType String,
          bounce_bouncedRecipients String,
          bounce_timestamp Timestamp,
          -- message Json,
          PRIMARY KEY (saved_datetime, eventid)
      )
      ```

  1. Click ![image](../../_assets/console-icons/play-fill.svg) **Run**.

      After you run the query, a new `postbox_events` table will appear in your database.

{% endlist %}


## Create a data stream in Data Streams {#stream}

Create a [data stream](../../data-streams/concepts/glossary.md#stream-concepts) to log Yandex Cloud Postbox events:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Data Streams** and click **Create stream**.
  1. In the **Database** field, select the `postbox-events-ydb` database you created earlier.
  1. In the **Name** field, enter the stream name: `postbox-events-stream`.
  1. In the **Pricing Mode** field, select `Actual usage`.
  1. Do not edit the other data stream settings. Click **Create**.

{% endlist %}

Wait for the stream to start. Once the stream is ready for use, its status will change from `Creating` to `Active`.


## Set up Yandex Cloud Postbox resources {#postbox}

In Yandex Cloud Postbox, [configure](../../postbox/concepts/glossary.md#subscription) event logging to Data Streams, create a sender [address](../../postbox/concepts/glossary.md#adress), and [verify](../../postbox/operations/check-domain.md) your domain ownership.


### Create a Yandex Cloud Postbox configuration {#config}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Cloud Postbox**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/list-ul.svg) **Configurations** and click **Create configuration**.
  1. In the **Name** field, specify the configuration name: `postbox-events-config`.
  1. Under **Subscriptions**, click **Add** and fill out the form that opens:

      1. In the **Name** field, specify the [subscription](../../postbox/concepts/glossary.md#subscription) name: `postbox-events-subscribe`.
      1. In the **Data stream** field, select the [data stream](../../data-streams/concepts/glossary.md#stream-concepts) named `postbox-events-stream`.
      1. Toggle the **Enabled** option on to activate the subscription.

  1. Do not edit the other configuration settings. Click **Create configuration**.

{% endlist %}


### Create a Yandex Cloud Postbox address {#address}

1. Generate the `privatekey.pem` key to create a DKIM signature by running this command in the terminal:

    ```bash
    openssl genrsa -out privatekey.pem 2048
    ```

    {% note info %}

    `openssl` comes preinstalled in Linux and macOS. If using Windows, you need to install it manually. For more information, refer to the [project's website](https://openssl-library.org/).

    {% endnote %}

1. Create a Yandex Cloud Postbox address:

    {% list tabs group=instructions %}

    - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
      1. Navigate to **Cloud Postbox**.
      1. In the left-hand panel, select ![at](../../_assets/console-icons/at.svg) **Addresses** and click **Create address**.
      1. In the **Domain** field, specify the domain you will use to send emails. You can use a domain of any level, as long as you own it.
      1. In the **Selector** field, specify a selector, e.g., `postbox`. Make sure to only use this selector in the resource record you create when [verifying domain ownership](#domain).
      1. In the **Configuration** field, select `postbox-events-config` you previously created.
      1. In the **Private key** field, paste the contents of the `privatekey.pem` file from the previous step.
      1. Do not change the other address settings. Click **Create address**.
      1. Click the newly created address in the list that opens.
      1. Under **Signature verification** on the address info page, copy and save the [TXT record](../../dns/concepts/resource-record.md#txt) from the **Value** field.

    {% endlist %}


### Verify your domain ownership {#domain}

To send emails, confirm domain ownership. After creating an address, DKIM signature settings will be generated on its page. Specify them as the values of the resource records you need to add to your domain zone. You can add the records via your registrar or in [Yandex Cloud DNS](../../dns/index.md), if you have delegated your Yandex Cloud domain.

{% list tabs group=dkim %}

- Simple setup {#easy}

    With the simple setup, Yandex Cloud Postbox automatically generates DKIM keys. The two CNAME records you need to add to your DNS provider are displayed under **Email signature configuration (DKIM)** on the address page.

    **Example of creating resource records in Yandex Cloud DNS**

    1. In the [management console](https://console.yandex.cloud), select the folder containing the address and your domain zone.
    
       If you do not have a [public DNS zone](../../dns/concepts/dns-zone.md#public-zones) yet, [create](../../dns/operations/zone-create-public.md) one:
    1. Navigate to **Cloud Postbox**.
    1. Select the new address and open the **Email signature configuration (DKIM)** section.
    1. For each of the two CNAME records, complete the following steps:
    
        1. Navigate to **Cloud DNS**.
        1. Select your domain zone.
        1. Click **Create record**.
        1. In the **Type** field, select `CNAME`.
        1. Enter the record name from the **Email signature configuration (DKIM)** section on the address page into the **Name** field, omitting the domain.
    
           {% note info %}
    
           Other DNS services may require a full record name, including the domain.
    
           {% endnote %}
    
        1. In the **Data** field, paste the record value from the **Email signature configuration (DKIM)** section on the address page.
        1. In the **TTL (in seconds)** field, specify the record lifetime.
        1. Click **Create**.
    1. Navigate to **Cloud Postbox**.
    1. Select the address you created.
    1. Wait for Yandex Cloud Postbox to verify the DKIM signature settings. If the records are correct, the verification status on the address page will change to `Success`.

- Advanced setup {#advanced}

    With the advanced setup, you need to manually [generate the key](../../postbox/operations/create-address.md) for the DKIM signature. The **Email signature configuration (DKIM)** section on the address page displays a single TXT record you need to add to your DNS provider.

    **Example of creating resource records in Yandex Cloud DNS**
    
    1. In the [management console](https://console.yandex.cloud), select the folder containing the address and your domain zone.

        If you do not have a [public DNS zone](../../dns/concepts/dns-zone.md#public-zones) yet, [create](../../dns/operations/zone-create-public.md) one:
    1. Navigate to **Cloud DNS**.
    1. Select your domain zone.
    1. Click **Create record**.
    1. In the **Name** field, specify the name portion generated when creating the address, omitting the domain in `<selector>._domainkey` format, e.g., `postbox._domainkey`.

        {% note info %}

        For other DNS services, you may need to copy the entire record. The final record must look like this: `<selector>._domainkey.<domain>.`, e.g., `postbox._domainkey.example.com.`.

        {% endnote %}

    1. In the **Type** field, select `TXT`.
    1. Paste the contents of the **Value** field under **Email signature configuration (DKIM)** into the **Data** field. Note that the record value must be enclosed in quotes, such as follows:

        ```text
        "v=DKIM1;h=sha256;k=rsa;p=M1B...aCA8"
        ```

        {% note info %}

        Other DNS services may have different requirements for resource record formatting. For more information, refer to your DNS provider’s guides.

        {% endnote %}

    1. In the **TTL (in seconds)** field, specify the record lifetime.
    1. Click **Create**.
    1. Navigate to **Cloud Postbox**.
    1. Select the address you created.
    1. Wait for Yandex Cloud Postbox to verify the DKIM signature settings. If the record is correct, the verification status on the address page will change to `Success`.

{% endlist %}

DNS server responses are cached, so you may experience delays when updating the resource record. If the verification status does not change within 24 hours, click **Run verification**.


## Set up Cloud Functions resources {#serverless-functions}

Create a [function](../../functions/concepts/function.md) to send data from the stream to the database, and a [trigger](../../functions/concepts/trigger/index.md) to invoke the function when events are logged to the data stream.


### Get the function code {#code}

{% list tabs %}

- Archive

  [Download](https://github.com/yandex-cloud-examples/yc-postbox-events/raw/main/build/postbox-events.zip) the `postbox-events.zip` archive to your computer. This archive contains the `index.py` and `requirements.txt` files with the function code.

- Repository

  On your computer, do the following:

  1. Clone the [repository](https://github.com/yandex-cloud-examples/yc-postbox-events/tree/main) with the function code:

      ```bash
      git clone https://github.com/yandex-cloud-examples/yc-postbox-events/blob/main/build/postbox-events.git
      ```

      Navigate to the repository directory. Make sure it contains the `index.py` and `requirements.txt` files with the function code.

  1. Create an archive named `postbox-events.zip` and add `index.py` and `requirements.txt` to it.

{% endlist %}


### Get the database connection credentials {#db-details}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Managed Service for&nbsp;YDB**.
  1. Select the database for which you need to get the endpoint and path.

      * The database endpoint is specified under **Connection** in the first part of the **Endpoint** field value (preceding `/?database=`):

          >For example, the endpoint of a serverless database is `grpcs://ydb.serverless.yandexcloud.net:2135`.

      * The database path is specified under **Connection** in the second part of the **Endpoint** field value (following `/?database=`).

          >Here is an example of a database path: `/ru-central1/b1gia87mbaomkfvs6rgl/etnudu2n9ri35luqe4h1`.

{% endlist %}


### Create a function {#function}

To create a function, you will need the function code and database connection credentials.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Cloud Functions**.
  1. Create a function:

      1. Click **Create function**.
      1. In the **Name** field, enter a name for the function, e.g., `postbox-events-function`.
      1. Click **Create**.

  1. Create a function version:

      1. In the **Editor** window that opens, select `Python 3.12`.
      1. Disable **Add files with code examples**.
      1. Click **Continue**.
      1. In the **Code source** field, select `ZIP archive`.
      1. Click **Attach file** and select `postbox-events.zip`.
      1. In the **Entry point** field, specify `index.handler`.

      1. Under **Parameters**, specify:

          * **Timeout**: `10 seconds`.
          * **Memory**: `128 MB`.
          * **Service account**: `yds-functions`.
          * **Environment variables**:

              Key | Description | Value (example)
              :--- | :--- | :---
              `YDB_DATABASE` | Database path     | `/ru-central1/b1go123e9vjq********/etnu15kr22********`
              `YDB_ENDPOINT` | Database endpoint | `grpcs://ydb.serverless.yandexcloud.net:2135`
              `YDB_TABLE`    | Table name | `postbox_events`

      1. Click **Save changes**.

{% endlist %}


### Create a trigger {#trigger}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
  1. Navigate to **Cloud Functions**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/gear-play.svg) **Triggers** and click **Create trigger**.
  1. In the **Name** field, enter the trigger name: `postbox-events-trigger`.
  1. In the **Type** field, select `Data Streams`.
  1. In the **Launched resource** field, select `Function`.
  1. Under **Data Streams settings**, select `postbox-events-stream` and the `yds-functions` service account.
  1. Under **Function settings**, select the `postbox-events-function` function and the `yds-functions` service account.
  1. Click **Create trigger**.

{% endlist %}


## Send emails {#send-letters}

1. Use the Yandex Cloud Postbox address and static access key you created earlier to [send](../../postbox/operations/send-email.md#send-email) several test emails in any way you prefer.
1. Make sure the emails were delivered by checking the mailbox you sent them to.
1. Make sure the data about sent emails reaches the services:

    {% list tabs group=instructions %}

    - Management console {#console}

      * Check the data stream:

          1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
          1. Navigate to **Data Streams**.
          1. Select the data stream named `postbox-events-stream`.
          1. Navigate to the ![text-align-justify](../../_assets/console-icons/text-align-justify.svg) **Data viewer** tab.
          
              The charts should show email sending events.

      * Check the database:

          1. In the [management console](https://console.yandex.cloud), select the folder where you are deploying your infrastructure.
          1. Navigate to **Managed Service for&nbsp;YDB**.
          1. Select the `postbox-events-ydb` database.
          1. Go to the ![image](../../_assets/console-icons/folder.svg) **Navigation** tab.
          1. Select the `postbox_events` table.

              The table should show new entries. Some columns may have the `NULL` value: this depends on the [type of notification](../../postbox/concepts/notification.md#types) received from Yandex Cloud Postbox.

    {% endlist %}


## Configure visualization in DataLens {#datalens}

To monitor the emails you send, set up a [connection](../../datalens/concepts/connection/index.md), create a [dataset](../../datalens/dataset/index.md), [charts](../../datalens/concepts/chart/index.md), and a [dashboard](../../datalens/concepts/dashboard.md).


### Create a connection {#connection}

{% list tabs group=instructions %}

- DataLens UI {#console}

  1. Go to the DataLens [home page](https://datalens.ru/?skipPromo=true).
  1. In the left-hand panel, select ![thunderbolt](../../_assets/console-icons/thunderbolt.svg) **Connections** and click **Create connection**.
  1. Select the **YDB** connector.
  1. Configure the connection as follows:

      * **Cloud and folder**: Select the folder you are using to complete this tutorial.
      * **Service account**: `yds-functions`.
      * **Database**: `postbox-events-ydb`.
      * **Cache TTL in seconds**: `Default`.
      * Enable the **SQL query access level** option and select `Allow subqueries in datasets`.

  1. Click **Create connection**.
  1. In the window that opens, select a workbook for your new connection and click **Create**.
  1. Enter `postbox-events-connection` as your connection name, and click **Create**.

{% endlist %}


### Create a dataset {#dataset}

{% list tabs group=instructions %}

- DataLens UI {#console}

  1. Go to the DataLens [home page](https://datalens.ru/promo).
  1. Click **Start in cloud**.
  1. In the left-hand panel, select ![circles-intersection](../../_assets/console-icons/circles-intersection.svg) **Datasets** and click **Create dataset**.
  1. In the window that opens, select the workbook with your new connection and click **Create**.
  1. Under **Connections**, click ![plus](../../_assets/console-icons/plus.svg) **Add** and select `postbox-events-connection` you created earlier.
  1. Under **Tables**, select the `postbox-events` table and drag it to the right.
  1. Click **Save**.
  1. In the window that opens, specify `postbox-events-dataset` as the dataset name and click **Create**.

{% endlist %}


### Create charts {#charts}

In this tutorial, we will create the [Events by day](#events-by-days) and [Event list](#events-list) charts as an example. You can create other charts in the same way.


#### Events by day {#events-by-days}

{% list tabs group=instructions %}

- DataLens UI {#console}

  1. Go to the DataLens [home page](https://datalens.ru/?skipPromo=true).
  1. In the left-hand panel, select ![chart-column](../../_assets/console-icons/chart-column.svg) **Charts**. Click **Create chart** and select **Chart in Wizard**.
  1. In the window that opens, select the workbook with your new connection and click **Create**.
  1. In the left-hand section, click ![circles-intersection](../../_assets/console-icons/circles-intersection.svg) **Select dataset** and select `postbox-events-dataset`.
  1. Select **Column chart** as the [chart type](../../datalens/visualization-ref/line-chart.md).
  1. Drag the dimensions as follows:

      * `delivery_timestamp` to the **X** section: Dates will be plotted along the X axis.
      * `eventid` to the **Y** section: Number of events will be plotted on the Y axis.
      * `eventtype` to the **Colors** section: This enables using a different color for each event type.

  1. Click **Save**.
  1. In the window that opens, enter `Events by day` as the chart name, and click **Save**.

{% endlist %}


#### Event list {#events-list}

{% list tabs group=instructions %}

- DataLens UI {#console}

  1. Go to the DataLens [home page](https://datalens.ru/?skipPromo=true).
  1. In the left-hand panel, select ![chart-column](../../_assets/console-icons/chart-column.svg) **Charts**. Click **Create chart** and select **Chart in Wizard**.
  1. In the window that opens, select the workbook with your new connection and click **Create**.
  1. In the left-hand section, click ![image](../../_assets/console-icons/circles-intersection.svg) **Select dataset** and select `postbox-events-dataset`.
  1. Select **Table** as the [chart type](../../datalens/visualization-ref/line-chart.md).
  1. Drag the following dimensions to the **Columns** section:

      * `saved_datetime`: Date and time of saving the event.
      * `eventid`: Event type.
      * `mail_ch_to`: Recipient's email address.
      * `delivery_timestamp`: Email delivery date and time.
      * `delivery_time_ms`: Delivery time in milliseconds.
      * `mail_ch_subject`: Email subject.
      * `bounce_bounceType`: Delivery error type.
      * `bounce_bounceSubType`: Non-delivery report.

  1. Drag the `delivery_timestamp` dimension to the **Sorting** section to sort the table by delivery time.
  1. Click **Save**.
  1. In the window that opens, enter `Event list` as the chart name, and click **Save**.

{% endlist %}


### Create a dashboard {#dashboard}

{% list tabs group=instructions %}

- DataLens UI {#console}

  1. Go to the DataLens [home page](https://datalens.ru/?skipPromo=true).
  1. In the left-hand panel, select ![layout-cells-large](../../_assets/console-icons/layout-cells-large.svg) **Dashboards** and click **Create dashboard**.
  1. In the window that opens, select the workbook with your new connection and click **Create**.
  1. Add `Events by day`, `Event list`, and other charts you created earlier to your dashboard:

      1. In the bottom panel, click **Chart**.
      1. In the window that opens, click **Select** and select the `Events by day` chart.
      1. Click **Add**.
      1. Repeat these steps to add to the dashboard the `Event list` chart and other charts as needed.

  1. Use your mouse to resize and move the charts around.
  1. Click **Save**.
  1. In the window that opens, enter `postbox-events-dashboard` as the dashboard name.
  1. Click **Create**.

{% endlist %}

After completing this tutorial, you can use charts and tables to analyze events.


## How to delete the resources you created {#clear-out}

To stop paying for the resources you created:

1. [Delete](../../functions/operations/trigger/trigger-delete.md) the trigger invoking the function in Cloud Functions.
1. [Delete](../../functions/operations/function/function-delete.md) the function in Cloud Functions.
1. [Delete](../operations/manage-databases.md#delete-db) the Managed Service for YDB database.
1. [Delete](../../data-streams/operations/manage-streams.md#delete-data-stream) the stream in Data Streams.
1. [Delete](../../postbox/operations/index.md) the Yandex Cloud Postbox address and configuration.
1. Optionally, [delete](../../iam/operations/sa/delete.md) the service accounts.
1. Optionally, delete the [resource record](../../dns/operations/resource-record-delete.md) and [public DNS zone](../../dns/operations/zone-delete.md).