Yandex Cloud Examples

repository·master·Indexed 41 days ago

https://github.com/yandex-cloud/examples

A collection of implementation examples for Yandex Cloud services, including IoT Core MQTT server interactions using Paho (C#, C++, Go, Android), ESP8266 integration via PubSubClient, and Serverless functions for processing MQTT messages.

Tokens
42.4K
Snippets
128
Records
188
Agent score
49%

What's inside Yandex Cloud Examples

  1. Monitor status of geo-distributed devices

    master

    This scenario demonstrates how to monitor the status of geographically distributed devices (e.g., vending machines) using Yandex Cloud serverless services. The architecture uses Yandex IoT Core for device connectivity, a PostgreSQL cluster for data storage, and Yandex DataLens for visualization.

    Key components include:

    • Yandex IoT Core: Receives MQTT messages from devices.
    • Yandex Cloud Functions: Processes incoming data and emulates devices.
    • Yandex Managed Service for PostgreSQL: Stores telemetry data.
    • Yandex DataLens: Provides visual dashboards for monitoring.
  2. Understand the GitHub Actions workflows used in the Django Serverless CI/CD example

    master

    This project demonstrates a CI/CD pipeline for deploying Serverless applications in Yandex Cloud using GitHub Actions. It utilizes a mix of community-maintained actions and custom reusable workflows to manage the application lifecycle.

    Community Actions Used:

    • yc-actions: Collection of ready-to-use actions for managing Yandex Cloud resources.
    • actions/checkout: Standard action to check out repository code.
    • mathieudutour/github-tag-action: Used for tagging application releases with version numbers.
    • frenck/action-setup-yq: Sets up the yq utility in the workflow.
    • actions/setup-python: Prepares the Python environment.
    • cuchi/jinja2-action: Enables file templating during workflow execution using jinja.

    Custom Reusable Workflows implemented in this project:

    • .github/workflows/build.yaml: Builds the application into a Docker image and publishes it to Yandex Container Registry.
    • .github/workflows/deploy-stage.yaml: Deploys the application to a specified environment (stage) and runs end-to-end (e2e) tests.
    • .github/workflows/delete-stage.yaml: Deletes a selected environment/stage.
    • .github/workflows/pr-comment.yaml: Adds or updates comments on Pull Requests.
  3. IoT Scenarios using Terraform in Yandex Cloud

    master

    This directory contains Terraform examples for deploying IoT scenarios within Yandex Cloud. The examples demonstrate how to set up infrastructure for device emulation and data ingestion.

    Available scenarios:

    1. Device Emulation: Uses Yandex Cloud Functions to emulate IoT devices (emulator_publish).
    2. Data Ingestion to PostgreSQL: Uses Yandex Cloud Functions to subscribe to device data and write it into a PostgreSQL database (subscribe_and_postgresql).
  4. Implement Server Room Monitoring with Serverless Services

    master

    This scenario demonstrates how to create a dashboard for monitoring sensor data and configuring alerts using Yandex Cloud serverless services (without virtual machines). It can be adapted for monitoring network equipment, industrial machinery, air quality, or climate control systems.

    Data Model

    Sensors transmit data via MQTT once per minute in the following JSON format:

    {
        "DeviceId":"e7a68b2d-464e-4222-88bd-c9e8d10a70cd",
        "TimeStamp":"2020-05-21T10:16:43Z",
        "Values":[
            {"Type":"Float","Name":"Humidity","Value":"12.456"},
            {"Type":"Float","Name":"Temperature","Value":"-23.456"},
            {"Type":"Bool","Name":"Water sensor","Value":"false"},
            {"Type":"Bool","Name":"Smoke sensor","Value":"false"},
            {"Type":"Bool","Name":"Room door sensor","Value":"true"},
            {"Type":"Bool","Name":"Rack door sensor","Value":"false"}
        ]
    }
  5. Integrate Nginx logs with Yandex Data Stream and Yandex Database

    master
    This project demonstrates how to parse and deliver Nginx logs using a pipeline of Yandex Cloud services. The architecture uses Yandex Data Stream (YDS) to receive logs, a Cloud Function to parse the logs (using logic from index.js and package.json), Yandex Data Transfer to move the parsed data, and Yandex Database (YDB) as the final storage destination.
  6. Scenario: Transfer IoT data to Managed PostgreSQL via Serverless Functions

    master

    This scenario demonstrates how to ingest data from IoT devices through Yandex IoT Core and save it into Yandex Managed Service for PostgreSQL using a Yandex Cloud Function as a bridge.

    Data Format

    The example uses an air quality sensor that emits JSON payloads containing temperature, humidity, pressure, and CO2 levels.

    Example Payload:

    {
        "DeviceId":"0e3ce1d0-1504-4325-972f-55c961319814",
        "TimeStamp":"2020-05-21T22:53:16Z",
        "Values":[
            {"Type":"Float","Name":"Humidity","Value":"25.281837"},
            {"Type":"Float","Name":"CarbonDioxide","Value":"67.96608"},
            {"Type":"Float","Name":"Pressure","Value":"110.7021"},
            {"Type":"Float","Name":"Temperature","Value":"127.708824"}
            ]
    }

    Architecture Components

    • Python Script: The logic for the Cloud Function is located in iotadapter.py.
    • Terraform Scripts: Automates the deployment of:
      • Yandex Managed Service for PostgreSQL
      • Yandex IoT Core
      • Yandex Cloud Functions (with triggers to capture IoT Core messages and save them to PostgreSQL).
  7. MQTT Client Example with Paho Library

    master

    This example demonstrates how to interact with a Yandex Cloud MQTT server using the Paho library. The example implements an 'echo' pattern: messages sent to the topic $devices/<device_id>/events are returned to the client via a subscription from the registry, which are then printed to the console.

    Prerequisites

    1. Create a Registry.
    2. Create a Device within that registry.

    Authentication Methods

    The example supports two authorization methods:

    • Certificates: Uses X.509 certificates for both the device and the registry.
    • Login/Password: Uses the unique IDs of the registry and device as logins, paired with generated passwords.
  8. IoT Sensor Data Format

    master

    The IoT scenarios in this repository use air sensor data as a source. The sensor outputs data in a JSON format containing a DeviceId, a TimeStamp, and an array of Values (e.g., Temperature, Humidity, Pressure, and CO2 levels).

    {
     "DeviceId":"0e3ce1d0-1504-4325-972f-55c961319814",
     "TimeStamp":"2020-05-21T22:53:16Z",
     "Values":[
         {"Type":"Float","Name":"Humidity","Value":"25.281837"},
         {"Type":"Float","Name":"CarbonDioxide","Value":"67.96608"},
         {"Type":"Float","Name":"Pressure","Value":"110.7021"},
         {"Type":"Float","Name":"Temperature","Value":"127.708824"}
         ]
    }
  9. Understand the CI/CD Environments and Infrastructure

    master

    The demo uses a multi-environment architecture to isolate testing from production. Each environment is isolated at the Yandex Identity and Access Management (IAM) level using separate directories and resources.

    Environments

    • prod: The production environment accessible to users.
    • testing: A testing environment used to verify the application before releasing to prod.

    Infrastructure Components

    • infra directory: A shared directory used to store all built Docker images.
    • Service Accounts:
      • prod and testing service accounts have read-only access to the infra directory to pull images.
      • A dedicated builder service account is responsible for publishing images to the infra directory.

    Automated Pipeline Flow

    When a .gitlab-ci.yml configuration is added, the following automated process occurs:

    1. Build: An image is built from the current branch and pushed to the Yandex Container Registry.
    2. Test Deploy: The application is deployed to the testing environment.
    3. Test: The application is verified (currently using curl to check the availability of the home page).
    4. Cleanup: The test deployment is removed.
    5. Production Deploy: The application is deployed to the prod environment.

    Changes pushed or merged into the main branch automatically trigger this pipeline, ensuring that the deployed environment stays in sync with the code.

  10. Understand the deployment environments

    master

    The project uses three isolated environments to manage the application lifecycle. Isolation is achieved at the IAM level, where each environment has its own directory in Yandex Cloud and its own set of static resources (databases, service accounts, etc.).

    • prod: The production environment visible to end-users.
    • testing: A testing environment used to validate the application before a release to prod.
    • feature: A development environment used for creating temporary stands to debug and verify Pull Requests (PRs). Multiple stands can run simultaneously in this environment using a shared database.

    Image Management: All Docker images are published to a shared infra directory. Service accounts for prod, testing, and feature have read-only access to this directory, while a dedicated builder service account is responsible for publishing images.