Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Solutions
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex IoT Core
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Sending messages
    • Subscribing a device or registry to receive messages
    • Viewing the connection log
    • Creating a trigger for a topic
    • Managing registries
      • Getting information about registries
      • Creating a registry
      • Updating a registry
      • Deleting a registry
    • Managing devices
      • Managing topic aliases
        • Creating an alias
        • Getting a list of aliases
        • Updating an alias
        • Deleting an alias
      • Getting information about devices
      • Creating a device
      • Updating a device
      • Deleting a device
    • Managing certificates
      • Create a certificate
      • Managing registry certificates
      • Managing device certificates
    • Managing passwords
      • Managing registry passwords
      • Managing device passwords
  • Concepts
    • Authorization
    • Relationship between service resources
    • MQTT broker connection parameters
    • Sending messages to an MQTT broker via gRPC
    • Topic
    • Backups
    • Quotas and limits
  • Use cases
    • All use cases
    • Working with Mosquitto
      • Sending messages
      • Subscribing a device or registry to receive messages
    • Working with Yandex IoT Core from an Android device in Java
    • Working with Yandex IoT Core in C#
    • Working with Yandex IoT Core in Java
    • Writing data from a device to Managed Service for PostgreSQL
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • DeviceDataService
      • DeviceService
      • RegistryDataService
      • RegistryService
      • OperationService
    • REST
      • Overview
      • Device
        • Overview
        • addCertificate
        • addPassword
        • create
        • delete
        • deleteCertificate
        • deletePassword
        • get
        • list
        • listCertificates
        • listOperations
        • listPasswords
        • update
      • DeviceData
        • Overview
        • publish
      • Registry
        • Overview
        • addCertificate
        • addPassword
        • create
        • delete
        • deleteCertificate
        • deletePassword
        • get
        • list
        • listCertificates
        • listDeviceTopicAliases
        • listOperations
        • listPasswords
        • update
      • RegistryData
        • Overview
        • publish
  • Questions and answers
  1. Step-by-step instructions
  2. Creating a trigger for a topic

Creating a trigger

  • Before you start
  • Creating a trigger
  • Checking the result

Create a trigger for the device topic or Yandex IoT Core service registry, and process message copies using a function Cloud Functions.

Warning

The trigger must be in the same cloud with the registry or device it reads messages from.

Before you start

To create a trigger, you need:

  1. Functions the trigger will send messages to for processing. If you don't have a function:
    • Create a function.
    • Create a function version.
  2. Registries or devices whose topics the trigger will accept copies of messages from. If you don't have these:
    • Create a registry.
    • Create a device.
  3. The Dead Letter Queue where messages that the function couldn't process are moved. If you don't have a queue, create one.
  4. Service accounts with rights to invoke the function and write messages to the Dead Letter Queue. You can use the same service account or different ones. If you don't have a service account, create one.

Creating a trigger

Note

The trigger is initiated within 5 minutes of being created.

Management console
CLI
API
  1. In the management console, go to the folder where you want to create a trigger.
  2. Open Cloud Functions.
  3. Go to the Triggers tab.
  4. Click Create trigger.
  5. Under Basic parameters:
    • Enter a name and description for the trigger.
    • In the Type field, select Yandex IoT Core.
  6. Under Yandex IoT Core message settings, specify the registry, device, and MQTT topic to create a trigger for. If you're creating a trigger for a registry topic, you can omit the device.
  7. Under Function settings:
    • Select the function for the trigger to invoke.
    • Specify the function version tag.
    • Specify the service account to be used to invoke the function.
  8. Under Repeat request settings:
    • In the Interval field, specify the time after which the function will be invoked again if the current attempt fails. Acceptable values are from 10 to 60 seconds.
    • In the Number of attempts field, specify the number of invocation retries before the trigger moves a message to the Dead Letter Queue. Acceptable values are from 1 to 5.
  9. Under Dead Letter Queue settings, select the Dead Letter Queue and service account with rights to write messages to it.
  10. Click Create trigger.

If you don't have the Yandex.Cloud command line interface yet, install and initialize it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To create a trigger, run the command:

yc serverless trigger create internet-of-things \
    --name <trigger name> \
    --registry-id <registry ID> \
    --device-id <device ID> \
    --mqtt-topic '$devices/<device ID>/events' \
    --invoke-function-id <function ID> \
    --invoke-function-service-account-id <service account ID> \
    --retry-attempts 1 \
    --retry-interval 10s \
    --dlq-queue-id <Dead Letter Queue ID> \
    --dlq-service-account-id <service account ID>

where:

  • --name: Trigger name.
  • --registry-id: Registry ID.
  • --device-id: Device ID. If you're creating a trigger for a registry topic, you can omit this parameter.
  • --mqtt-topic: The topic you want to create a trigger for.
  • --invoke-function-id: Function ID.
  • --invoke-function-service-account-id: Service account with rights to invoke the function.
  • --retry-attempts: The time after which the function will be invoked again if the current attempt fails. Values can be from 10 to 60 seconds. The default is 10 seconds.
  • --retry-interval: The number of invocation retries before the trigger moves a message to the Dead Letter Queue. Values can be from 1 to 5. The default is 1.
  • --dlq-queue-id: ID of the Dead Letter Queue.
  • --dlq-service-account-id: Service account with rights to write messages to the Dead Letter Queue.

Result:

id: a1sl0mkmimfj3uv52fr8
folder_id: b1g88tflru0ek1omtsu0
created_at: "2019-09-25T13:54:35.654935Z"
name: iot-trigger
rule:
  iot_message:
    registry_id: arenou2oj4ct42eq8g3n
    device_id: areqjd6un3afc3cefcvm
    mqtt_topic: $devices/areqjd6un3afc3cefcvm/events
    invoke_function:
      function_id: d4eofc7n0m03lmudse8l
      function_tag: $latest
      service_account_id: aje3932acd0c5ur7dagp
      retry_settings:
        retry_attempts: "1"
        interval: 10s
status: ACTIVE

You can create a trigger for Yandex IoT Core using the create API method.

Checking the result

Make sure the trigger is working properly. To do this, view the function logs that show information about its invocations.

In this article:
  • Before you start
  • Creating a trigger
  • Checking the result
Language / Region
Careers
Privacy policy
Terms of use
Brandbook
© 2021 Yandex.Cloud LLC