Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • 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
  • Create a trigger
  • Check the results

Triggers is currently at the Preview stage.

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. A service account with rights for function call. If you don't have a service account, create one.
  2. Registries or device whose topics the trigger will accept copies of messages from. If you don't have either:
    • Create a registry.
    • Create a device.
  3. Functions the trigger will send messages to for processing. If you don't have a function:
    • Create a function.
    • Create a version of the function and upload the function code to it.

Create a trigger

Create a trigger for the device topic.

Note

The trigger is initiated within 5 minutes of being created.

Management console
CLI

To create a trigger:

  1. In the management console, select the folder where you want to create a trigger.
  2. Select Cloud Functions.
  3. In the left part of the window, select Triggers.
  4. Click Create trigger.
  5. In the Name field, enter the trigger name.
  6. In the Type drop-down list, select Yandex IoT Core.
  7. Under Yandex IoT Core message settings, enter the parameters previously set for your registry and device:
    • Registry: Select the registry with the desired device.
    • Device: Select the desired device.
    • MQTT topic: Enter the topic to create a trigger for.
  8. Under Function settings, enter the parameters previously set for your function:
    • Function: Select the desired function.
    • Service account: Select the service account to perform the function for.
  9. Click "Create trigger".

The trigger is created and displayed in the table's Triggers section.

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.

Create a trigger:

  • --name: Trigger name.
  • --registry-id: A unique registry ID.
  • --device-id: The unique device ID. If you are creating a trigger for a registry topic, you can skip this parameter.
  • --mqtt-topic: The topic you want to create a trigger for.
  • --invoke-function-id: Unique function ID.
  • --invoke-function-service-account-id: Service account with rights to call the function.
$ 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>

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

Check the results

Check the function logs to see if the function was run:

  1. The function logs should contain information about the function call. In this example, the function outputs information about the messages processed.

    $ yc serverless function logs <function ID>
    

    Result:

    2019-09-25 14:00:00     MESSAGE_BATCH
    2019-09-25 14:00:00     {
    2019-09-25 14:00:00       "event_metadata": {
    2019-09-25 14:00:00         "event_id": "9e016299-866f-4900-8830-d674cbff3577",
    2019-09-25 14:00:00         "event_type": "yandex.cloud.events.iot.IoTMessage",
    2019-09-25 14:00:00         "created_at": "2019-09-25T13:59:59.208724628Z"
    2019-09-25 14:00:00       },
    2019-09-25 14:00:00       "details": {
    2019-09-25 14:00:00         "registry_id": "arenou2oj4ct42eq8g3n",
    2019-09-25 14:00:00         "device_id": "areqjd6un3afc3cefcvm",
    2019-09-25 14:00:00         "mqtt_topic": "$devices/areqjd6un3afc3cefcvm/events",
    2019-09-25 14:00:00         "payload": "VGVzdCA0"
    2019-09-25 14:00:00       }
    2019-09-25 14:00:00     }
    2019-09-25 14:00:00     END RequestID: 1ba57cbe-c2ce-4d1a-91a3-9592e945b45a
    2019-09-25 14:00:00     REPORT RequestID: 1ba57cbe-c2ce-4d1a-91a3-9592e945b45a Duration: 368.362 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 13 MB
    
In this article:
  • Before you start
  • Create a trigger
  • Check the results
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC