Upload device-side logs to Amazon CloudWatch - Amazon IoT Core
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Upload device-side logs to Amazon CloudWatch

You can upload historical, device-side logs into Amazon CloudWatch to monitor and analyze a device's activity in the field. Device-side logs can include system, application, and device logs files. This process uses a CloudWatch Logs rules action parameter to publish device-side logs into a customer-defined log group.

How it works

The process begins when an Amazon IoT device sends MQTT messages containing formatted log files to an Amazon IoT topic. An Amazon IoT rule monitors the message topic and sends the log files to a CloudWatch Logs group that you define. You can then review and analyze the information.

MQTT topics

Choose an MQTT topic name space that you will use to publish the logs. We recommend using this format for the common topic space, $aws/rules/things/thing_name/logs, and this format for error topics, $aws/rules/things/thing_name/logs/errors. The naming structure for logs and error topics is recommended, but not required. For more information, see Designing MQTT Topics for Amazon IoT Core.

By using the recommended common topic space, you utilize Amazon IoT Basic Ingest reserved topics. Amazon IoT Basic Ingest securely sends device data to the Amazon services that are supported by Amazon IoT rule actions. It removes the publish/subscribe message broker from the ingestion path, making it more cost effective. For more information, see Reducing messaging costs with Basic Ingest.

If you use batchMode to upload log files, your messages must follow a specific format that includes a UNIX timestamp and message. For more information, see the MQTT message format requirements for batchMode topic within CloudWatch Logs rule action.

Rule action

When Amazon IoT receives the MQTT messages from the client devices, an Amazon IoT rule monitors the customer-defined topic and publishes the contents into a CloudWatch log group that you define. This process uses a CloudWatch Logs rule action to monitor MQTT for batches of log files. For more information, see the CloudWatch Logs Amazon IoT rule action.

Batch mode

batchMode is a Boolean parameter within the Amazon IoT CloudWatch Logs rule action. This parameter is optional and is off (false) by default. To upload device-side log files in batches, you must turn this parameter on (true) when you create the Amazon IoT rule. For more information, see CloudWatch Logs in the Amazon IoT rule actions section.