Get started with AWS IoT on LocalStack

LocalStack Pro supports IoT Core, IoT Data, IoT Analytics and related APIs. Common operations for creating and updating things, groups, policies, certificates and other entities are implemented with full CloudFormation support.

MQTT Broker

LocalStack ships with a built-in MQTT broker. To retrieve the MQTT endpoint, use the DescribeEndpoint operation.

$ awslocal iot describe-endpoint
    "endpointAddress": ""

This endpoint can then be used with any MQTT client to publish and subscribe to topics.

Lifecycle Events

LocalStack also publishes the lifecycle events to the standard endpoints.

  • $aws/events/presence/connected/clientId: when a client connects
  • $aws/events/presence/disconnected/clientId: when a client disconnects
  • $aws/events/subscriptions/subscribed/clientId: when a client subscribes to a topic
  • $aws/events/subscriptions/unsubscribed/clientId: when a client unsubscribes from a topic

Currently the principalIdentifier and sessionIdentifier fields in event payload contain dummy values.

Registry Events for Things

LocalStack can publish the registry events, if you enable it.

$ awslocal iot update-event-configurations --event-configurations "{\"THING\":{\"Enabled\": true}}"

You can then subscribe or use topic rules on the follow topics:

  • $aws/events/thing/<thingName>/created: when a new Thing is created
  • $aws/events/thing/<thingName>/updated: when a Thing is updated
  • $aws/events/thing/<thingName>/deleted: when a Thing is deleted

Topic Rules

It is also possible to use advanced features like SQL queries for IoT topic rules.

For example, you can use the CreateTopicRule operation to define a topic rule with a SQL query SELECT * FROM 'my/topic' where attr=123 which will execute a trigger whenever a message with attribute attr=123 is received on the MQTT topic my/topic.

Supported triggers include Kinesis, Lambda, SQS, Firehose and DynamoDB v2.