Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex DataLens
  • DataLens neuroanalyst
    • Overview
      • Yandex Metrica: direct connection
      • Yandex Metrica: data export, post-processing, and visualization
      • AppMetrica: direct connection
      • AppMetrica: data export, post-processing, and visualization
      • Bitrix24: direct connection
      • Yandex Tracker: data export and visualization
      • Analyzing Object Storage logs with DataLens
      • Yandex Music podcasts: Statistics
      • Visualizing Yandex Query data
      • Visualizing Yandex Monitoring data
      • Visualizing YTsaurus CHYT data
      • Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them with Yandex DataLens
      • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
  • DataLens Gallery
  • Audit Trails events

In this article:

  • Get your cloud ready
  • Required paid resources
  • Create a service account
  • Set up a Managed Service for YDB database
  • Create a database
  • Create a table
  • Create a data stream in Data Streams
  • Set up Yandex Cloud Postbox and Cloud DNS resources
  • Create an address
  • Verify your domain ownership
  • Create a configuration
  • Set up Cloud Functions resources
  • Get the function code
  • Get the DB connection details
  • Create a function
  • Create a trigger
  • Send emails
  • Configure visualization in DataLens
  • Create a connection
  • Create a dataset
  • Create charts
  • Create a dashboard
  • How to delete the resources you created
  1. Tutorials
  2. Service analytics
  3. Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them with Yandex DataLens

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

Written by
Yandex Cloud
Updated at August 15, 2025
  • Get your cloud ready
    • Required paid resources
    • Create a service account
  • Set up a Managed Service for YDB database
    • Create a database
    • Create a table
  • Create a data stream in Data Streams
  • Set up Yandex Cloud Postbox and Cloud DNS resources
    • Create an address
    • Verify your domain ownership
    • Create a configuration
  • Set up Cloud Functions resources
    • Get the function code
    • Get the DB connection details
    • Create a function
    • Create a trigger
  • Send emails
  • Configure visualization in DataLens
    • Create a connection
    • Create a dataset
    • Create charts
    • Create a dashboard
  • How to delete the resources you created

In this tutorial, you will set up streaming of Yandex Cloud Postbox events to Yandex Data Streams and their visualization in Yandex DataLens for further analysis. Sending emails generates events.

You can implement all the solutions from this tutorial in the Yandex Cloud management console; no coding skills are required. To process and store data, you will use Yandex Cloud Functions and Yandex Managed Service for YDB.

To set up event streaming and visualization:

  1. Get your cloud ready.
  2. Set up a Managed Service for YDB database.
  3. Create a data stream in Data Streams.
  4. Set up Yandex Cloud Postbox and Cloud DNS resources.
  5. Set up Cloud Functions resources.
  6. Send emails.
  7. Configure visualization in DataLens.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The infrastructure support costs include:

  • Fee for YDB operations and data storage (see Yandex Managed Service for YDB pricing).
  • Data Streams data storage fee (see Yandex Data Streams pricing).
  • Fee for function invocation count, computing resources allocated to run the function, and outbound traffic (see Cloud Functions pricing).
  • Fee for using Yandex Cloud Postbox (see Yandex Cloud Postbox pricing).
  • Fee for the DataLens plan (see Yandex DataLens pricing).

Create a service accountCreate a service account

Management console
  1. In the management console, select the relevant folder.
  2. In the list of services, select Identity and Access Management.
  3. Click Create service account.
  4. Name the service account: yds-functions.
  5. Click Add role and select the yds.editor and functions.functionInvoker roles.
  6. Click Create.

Set up a Managed Service for YDB databaseSet up a Managed Service for YDB database

You can use any DBMS suitable for analytical tasks as event storage. In this tutorial, we use a Managed Service for YDB serverless database. For other DBMS, the SQL query for creating a table and code for loading events into that table may be different.

Create a databaseCreate a database

Management console
  1. In the management console, select the relevant folder.
  2. Select Managed Service for YDB.
  3. Click Create a database.
  4. Specify the DB Name: postbox-events-ydb.
  5. Under Database type, select Serverless.
  6. 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.

Create a tableCreate a table

Management console
  1. On the Databases page, select the postbox-events-ydb DB.

  2. To open the DB root directory, navigate to the Navigation tab.

  3. To create a DB query, click New SQL query in the top-right corner. The Query page will open.

  4. In the Query field, enter:

    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)
    )
    
  5. Click Run.

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

Create a data stream in Data StreamsCreate a data stream in Data Streams

Create a data stream to log events.

Management console
  1. In the management console, select Data Streams.
  2. Click Create stream.
  3. Specify the postbox-events-ydb database.
  4. Name the data stream: postbox-events-stream.
  5. Select the Actual usage pricing plan.
  6. Click Create.

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 and Cloud DNS resourcesSet up Yandex Cloud Postbox and Cloud DNS resources

Create a sending address, verify your domain ownership, and configure event logging to Data Streams.

Create an addressCreate an address

  1. On your computer, generate the privatekey.pem file for DKIM signing:

    Linux
    openssl genrsa -out privatekey.pem 2048
    
  2. Create an address:

    Management console
    1. In the management console, select Cloud Postbox.
    2. Click Create address.
    3. In the Domain field, specify the domain you will use to send emails. You can use a domain of any level.
    4. In the Selector field, specify a selector, e.g., postbox. Make sure to only use this selector in that single resource record you create at domain ownership verification.
    5. In the Private key field, copy the contents of the privatekey.pem file.
    6. Click Create address.

Verify your domain ownershipVerify your domain ownership

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 record you need to add to your domain zone. You can add a record with your registrar or in Yandex Cloud DNS if you have delegated your domain.

Example of creating a resource record in Cloud DNS

Management console
  1. In the management console, select the folder containing the address and your domain zone.

  2. Select Cloud DNS.

  3. Select your domain zone.

  4. Click Create record.

  5. 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

    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..

  6. In the Type list, select TXT.

  7. Copy the contents of the Value field from the Signature verification section and paste it into the Data field. Note that the record value must be enclosed in quotes, for example:

    "v=DKIM1;h=sha256;k=rsa;p=M1B...aCA8"
    
  8. Click Create.

  9. Go to Cloud Postbox.

  10. Select the address you created.

  11. Click Verify address. If the record is correct, the verification status on the address page will change to Success.

DNS server responses are cached, so delays may occur when updating a resource record.

Create a configurationCreate a configuration

Management console
  1. In the management console, select Cloud Postbox.

  2. In the left-hand panel, select Configurations.

  3. Click Create configuration.

  4. Name the configuration: postbox-events-config.

  5. Under Subscriptions, click Add:

    1. Enter the subscription name: postbox-events-subscribe.
    2. Select the postbox-events-stream data stream.
    3. Toggle the Enabled option on to activate the subscription.
  6. Click Create configuration.

Set up Cloud Functions resourcesSet up Cloud Functions resources

Create a function to send data from the stream to the DB, and a trigger to invoke the function when events are logged in the data stream.

Get the function codeGet the function code

Archive
Repository

Download the postbox-events.zip archive to your computer. The archive contains the index.py and requirements.txt files with the function code.

On your computer, do the following:

  1. Clone the repository with the function code:

    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.

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

Get the DB connection detailsGet the DB connection details

Management console
  1. Navigate to the management console.

  2. Select the folder with your DB and go to Managed Service for YDB.

  3. Select the DB for which you need to get the endpoint and path.

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

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

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

      Here is an example of a DB path: /ru-central1/b1gia87mbaomkfvs6rgl/etnudu2n9ri35luqe4h1.

Create a functionCreate a function

To create a function, you will need the function code and DB connection details.

Management console
  1. In the management console, select Cloud Functions.

  2. Create a function:

    1. Click Create function.
    2. In the Name field, enter a name for the function, e.g., postbox-events-function.
    3. Click Create.
  3. Create a function version:

    1. In the Editor window that opens, select Python 3.12.

    2. Disable Add files with code examples.

    3. Click Continue.

    4. In the Method field, select ZIP archive.

    5. Click Attach file and select postbox-events.zip.

    6. In the Entry point field, specify index.handler.

    7. Under Parameters, specify:

      • Timeout: 10

      • Memory: 128 MB

      • Service account: yds-functions

      • Environment variables:

        Key Description Value (example)
        YDB_DATABASE DB path /ru-central1/b1go123e9vjq********/etnu15kr22********
        YDB_ENDPOINT DB endpoint grpcs://ydb.serverless.yandexcloud.net:2135
        YDB_TABLE Table name postbox_events
    8. Click Save changes.

Create a triggerCreate a trigger

Management console
  1. In the management console, select Cloud Functions.
  2. In the left-hand panel, select Triggers.
  3. Click Create trigger.
  4. In the Name field, enter a name for the trigger, e.g., postbox-events-trigger.
  5. In the Type field, select Data Streams.
  6. In the Launched resource field, select Function.
  7. Under Data Streams settings, select the data stream named postbox-events-stream and the yds-functions service account.
  8. Under Function settings, select the function named postbox-events-function and the yds-functions service account.
  9. Click Create trigger.

Send emailsSend emails

  1. Create a service account named postbox-user with the postbox.sender role and static access keys.

  2. Send several test emails using the address you created earlier.

  3. Make sure the emails were sent: check the the destination inbox.

  4. Make sure data reaches the services:

    Management console
    1. Check the data stream:

      1. In the management console, select Data Streams.

      2. Select the data stream named postbox-events-stream.

      3. Navigate to the Data viewer tab.

        The charts should show data on the emails you sent.

    2. Check the DB:

      1. In the management console, select Managed Service for YDB.

      2. Select the postbox-events-ydb DB.

      3. Go to the Navigation tab.

      4. Select the postbox_events table.

        The table should show new records. Some columns may have the NULL value: this depends on the type of notification received from Yandex Cloud Postbox.

Configure visualization in DataLensConfigure visualization in DataLens

To monitor the emails you send, set up a connection, create a dataset, charts, and a dashboard.

Create a connectionCreate a connection

DataLens UI
  1. Go to the DataLens home page.

  2. Click Create connection.

  3. Select the YDB connector.

  4. 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.
    • SQL query access level: Allow subqueries from datasets and queries from charts.
  5. Click Create connection.

  6. Enter a connection name, e.g., postbox-events-connection, and click Create.

Create a datasetCreate a dataset

DataLens UI
  1. Go to the DataLens home page.
  2. Click Create dataset.
  3. In the left-hand panel, click Add.
  4. Select postbox-events-connection.
  5. In the left-hand menu, select the postbox-events table and drag it to the right.
  6. Click Save.
  7. In the window that opens, specify postbox-events-dataset and click Create.

Create chartsCreate charts

In this tutorial, we will create the Events by day and Event list charts as an example. You can create other charts in the same way.

Events by dayEvents by day

DataLens UI
  1. Go to the DataLens home page.

  2. Click Create chart.

  3. In the left-hand panel, click Select dataset and select postbox-events-dataset.

  4. Select Column chart as the chart type.

  5. 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.
  6. Click Save.

  7. In the window that opens, specify the chart name, Events by day, and click Save.

Event listEvent list

DataLens UI
  1. Go to the DataLens home page.

  2. Click Create chart.

  3. In the left-hand panel, click Select dataset and select postbox-events-dataset.

  4. Select Table as the chart type.

  5. 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.
  6. Drag the delivery_timestamp dimension to the Sorting section to sort the table by delivery time.

  7. Click Save.

  8. In the window that opens, specify the chart name, Event list, and click Save.

Create a dashboardCreate a dashboard

DataLens UI
  1. Go to the DataLens home page.

  2. Click Create dashboard.

  3. Add Events by day, Event list, and other charts you created earlier to your dashboard:

    1. In the bottom panel, click Chart.
    2. In the Chart field of the window that opens, click Select and select Events by day.
    3. Click Add.
    4. Repeat these steps to add other charts.
  4. Resize and move your charts as needed.

  5. Click Save.

  6. In the window that opens, name the dashboard: postbox-events-dashboard.

  7. Click Create.

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

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Delete the trigger invoking the function in Cloud Functions.
  2. Delete the function in Cloud Functions.
  3. Delete the Managed Service for YDB database.
  4. Delete the stream in Data Streams.
  5. Delete the Yandex Cloud Postbox address and configuration.

Was the article helpful?

Previous
Visualizing YTsaurus CHYT data
Next
Overview
© 2025 Direct Cursus Technology L.L.C.