Yandex Cloud Examples
repository·master·Indexed 41 days ago
https://github.com/yandex-cloud/examplesA 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.
What's inside Yandex Cloud Examples
- This project is a sample implementation of a video-to-GIF conversion service built entirely using Yandex Cloud serverless components. It uses a queue-based architecture to handle asynchronous processing tasks.
Monitor status of geo-distributed devices
masterThis 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.
Understand the GitHub Actions workflows used in the Django Serverless CI/CD example
masterThis 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 theyqutility in the workflow.actions/setup-python: Prepares the Python environment.cuchi/jinja2-action: Enables file templating during workflow execution usingjinja.
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.
IoT Scenarios using Terraform in Yandex Cloud
masterThis 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:
- Device Emulation: Uses Yandex Cloud Functions to emulate IoT devices (
emulator_publish). - Data Ingestion to PostgreSQL: Uses Yandex Cloud Functions to subscribe to device data and write it into a PostgreSQL database (
subscribe_and_postgresql).
- Device Emulation: Uses Yandex Cloud Functions to emulate IoT devices (
Implement Server Room Monitoring with Serverless Services
masterThis 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"} ] }Integrate Nginx logs with Yandex Data Stream and Yandex Database
masterThis 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 fromindex.jsandpackage.json), Yandex Data Transfer to move the parsed data, and Yandex Database (YDB) as the final storage destination.Find current Yandex Cloud examples
masterThis repository is archived and will be removed soon. For active and up-to-date examples of using Yandex Cloud services, please visit the official examples repository at https://github.com/yandex-cloud-examples.Scenario: Transfer IoT data to Managed PostgreSQL via Serverless Functions
masterThis 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).
- Python Script: The logic for the Cloud Function is located in
MQTT Client Example with Paho Library
masterThis 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>/eventsare returned to the client via a subscription from the registry, which are then printed to the console.Prerequisites
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.
IoT Sensor Data Format
masterThe IoT scenarios in this repository use air sensor data as a source. The sensor outputs data in a JSON format containing a
DeviceId, aTimeStamp, and an array ofValues(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"} ] }Understand the CI/CD Environments and Infrastructure
masterThe 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 toprod.
Infrastructure Components
infradirectory: A shared directory used to store all built Docker images.- Service Accounts:
prodandtestingservice accounts have read-only access to theinfradirectory to pull images.- A dedicated
builderservice account is responsible for publishing images to theinfradirectory.
Automated Pipeline Flow
When a
.gitlab-ci.ymlconfiguration is added, the following automated process occurs:- Build: An image is built from the current branch and pushed to the Yandex Container Registry.
- Test Deploy: The application is deployed to the
testingenvironment. - Test: The application is verified (currently using
curlto check the availability of the home page). - Cleanup: The test deployment is removed.
- Production Deploy: The application is deployed to the
prodenvironment.
Changes pushed or merged into the
mainbranch automatically trigger this pipeline, ensuring that the deployed environment stays in sync with the code.Understand the deployment environments
masterThe 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
infradirectory. Service accounts forprod,testing, andfeaturehave read-only access to this directory, while a dedicatedbuilderservice account is responsible for publishing images.