Logging Amazon IoT API calls using Amazon CloudTrail - 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).

Logging Amazon IoT API calls using Amazon CloudTrail

Amazon IoT is integrated with Amazon CloudTrail, a service that provides a record of actions taken by a user, role, or an Amazon service in Amazon IoT. CloudTrail captures all API calls for Amazon IoT as events, including calls from the Amazon IoT console and from code calls to the Amazon IoT APIs. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Amazon IoT. If you don't configure a trail, you can still view the most recent events in the CloudTrail console in Event history. Using the information collected by CloudTrail, you can determine the request that was made to Amazon IoT, the IP address from which the request was made, who made the request, when it was made, and other details.

To learn more about CloudTrail, see the Amazon CloudTrail User Guide.

Amazon IoT information in CloudTrail

CloudTrail is enabled on your Amazon Web Services account when you create the account. When activity occurs in Amazon IoT, that activity is recorded in a CloudTrail event along with other Amazon service events in Event history. You can view, search, and download recent events in your Amazon Web Services account. For more information, see Viewing Events with CloudTrail Event History.

For an ongoing record of events in your Amazon Web Services account, including events for Amazon IoT, create a trail. A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. By default, when you create a trail in the console, the trail applies to all Amazon Web Services Regions. The trail logs events from all Amazon Web Services Regions in the Amazon partition and delivers the log files to the Amazon S3 bucket that you specify. You can configure other Amazon services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see:


Amazon IoT data plane actions (device side) are not logged by CloudTrail. Use CloudWatch to monitor these actions.

Generally speaking, Amazon IoT control plane actions that make changes are logged by CloudTrail. Calls such as CreateThing, CreateKeysAndCertificate, and UpdateCertificate leave CloudTrail entries, while calls such as ListThings and ListTopicRules do not.

Every event or log entry contains information about who generated the request. The identity information helps you determine the following:

  • Whether the request was made with root or IAM user credentials.

  • Whether the request was made with temporary security credentials for a role or federated user.

  • Whether the request was made by another Amazon service.

For more information, see the CloudTrail userIdentity Element.

Amazon IoT actions are documented in the Amazon IoT API Reference. Amazon IoT Wireless actions are documented in the Amazon IoT Wireless API Reference.

Understanding Amazon IoT log file entries

A trail is a configuration that enables delivery of events as log files to an Amazon S3 bucket that you specify. CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested action, the date and time of the action, request parameters, and so on. CloudTrail log files are not an ordered stack trace of the public API calls, so they do not appear in any specific order.

The following example shows a CloudTrail log entry that demonstrates the AttachPolicy action.

{ "timestamp":"1460159496", "AdditionalEventData":"", "Annotation":"", "ApiVersion":"", "ErrorCode":"", "ErrorMessage":"", "EventID":"8bff4fed-c229-4d2d-8264-4ab28a487505", "EventName":"AttachPolicy", "EventTime":"2016-04-08T23:51:36Z", "EventType":"AwsApiCall", "ReadOnly":"", "RecipientAccountList":"", "RequestID":"d4875df2-fde4-11e5-b829-23bf9b56cbcd", "RequestParamters":{ "principal":"arn:aws:iot:us-east-1:123456789012:cert/528ce36e8047f6a75ee51ab7beddb4eb268ad41d2ea881a10b67e8e76924d894", "policyName":"ExamplePolicyForIoT" }, "Resources":"", "ResponseElements":"", "SourceIpAddress":"", "UserAgent":"aws-internal/3", "UserIdentity":{ "type":"AssumedRole", "principalId":"AKIAI44QH8DHBEXAMPLE", "arn":"arn:aws:sts::12345678912:assumed-role/iotmonitor-us-east-1-beta-InstanceRole-1C5T1YCYMHPYT/i-35d0a4b6", "accountId":"222222222222", "accessKeyId":"access-key-id", "sessionContext":{ "attributes":{ "mfaAuthenticated":"false", "creationDate":"Fri Apr 08 23:51:10 UTC 2016" }, "sessionIssuer":{ "type":"Role", "principalId":"AKIAI44QH8DHBEXAMPLE", "arn":"arn:aws:iam::123456789012:role/executionServiceEC2Role/iotmonitor-us-east-1-beta-InstanceRole-1C5T1YCYMHPYT", "accountId":"222222222222", "userName":"iotmonitor-us-east-1-InstanceRole-1C5T1YCYMHPYT" } }, "invokedBy":{ "serviceAccountId":"111111111111" } }, "VpcEndpointId":"" }