IoT Events

Jets supports IoT Events. This allows you to have a Lambda function run when IoT data is received. You provide a SQL statement to define an IoT Topic Rule. You can access the data via event.

IoT Overview

Simple Form

At a minimum, you need to define the SQL statement to use query the Topic Rule. This is the simplest and recommended form.

class ThermostatJob < ApplicationJob
  iot_event "SELECT * FROM 'my/topic'"
  def measure
    puts "event #{JSON.dump(event)}"
  end
end

The iot_event declaration creates an AWS::IoT::TopicRule.

Complete Form: Control with Different Argument Types

If you need more control, you can also set any of the properties of the topic_rule_payload by providing a hash.

class ThermostatJob < ApplicationJob
  iot_event(sql: "SELECT * FROM 'my/topic'")
  def record
    puts "event #{JSON.dump(event)}"
  end
end

For even more control, you can provide a hash that has a topic_rule_payload key. This will provide you full control over the properties passed to the AWS::IoT::TopicRule resource.

class ThermostatJob < ApplicationJob
  iot_event(topic_rule_payload: {sql: "SELECT * FROM 'my/topic'"})
  def act
    puts "event #{JSON.dump(event)}"
  end

Event Payloads

The event payload received is whatever is sent by the device to MQTT. You can test in the MQTT console.

You can also test with the aws iot-data publish cli:

aws iot-data publish --topic my/topic --payload '{"message": "test"}'

You should see the data in the Lambda function’s CloudWatch logs.

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub, and contributions are encouraged and welcomed. We love pull requests from you!