Logging Amazon IoT Greengrass API calls with Amazon CloudTrail - Amazon IoT Greengrass
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.

Amazon IoT Greengrass Version 1 no longer receives feature updates, and will receive only security patches and bug fixes until June 30, 2023. For more information, see the Amazon IoT Greengrass V1 maintenance policy. We strongly recommend that you migrate to Amazon IoT Greengrass Version 2, which adds significant new features and support for additional platforms.

Logging Amazon IoT Greengrass API calls with Amazon CloudTrail

Amazon IoT Greengrass 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 Greengrass. CloudTrail captures all API calls for Amazon IoT Greengrass as events. The calls captured include calls from the Amazon IoT Greengrass console and code calls to the Amazon IoT Greengrass API operations. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Amazon IoT Greengrass. 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 Greengrass, the IP address from which the request was made, who made the request, when it was made, and additional details.

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

Amazon IoT Greengrass information in CloudTrail

CloudTrail is enabled on your Amazon Web Services account when you create the account. When activity occurs in Amazon IoT Greengrass, 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 Greengrass, 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 Regions in the Amazon partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other Amazon services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see the following:

All Amazon IoT Greengrass actions are logged by CloudTrail and are documented in the Amazon IoT Greengrass API reference. For example, calls to the AssociateServiceRoleToAccount, GetGroupVersion, GetConnectivityInfo, and CreateFunctionDefinition actions generate entries in the CloudTrail log files.

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 Amazon Identity and Access Management (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.

Understanding Amazon IoT Greengrass 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 aren't an ordered stack trace of the public API calls, so they don't appear in any specific order.

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

{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::123456789012:user/Mary_Major", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major" }, "eventTime": "2018-10-17T17:04:02Z", "eventSource": "greengrass.amazonaws.com", "eventName": "AssociateServiceRoleToAccount", "awsRegion": "us-east-1", "sourceIPAddress": "203.0.113.12", "userAgent": "apimanager.amazonaws.com", "errorCode": "BadRequestException", "requestParameters": null, "responseElements": { "Message": "That role ARN is invalid." }, "requestID": "a5990ec6-d22e-11e8-8ae5-c7d2eEXAMPLE", "eventID": "b9070ce2-0238-451a-a9db-2dbf1EXAMPLE", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

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

{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::123456789012:user/Mary_Major", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "attributes": { "mfaAuthenticated": "false", "creationDate": "2018-10-17T18:14:57Z" } }, "invokedBy": "apimanager.amazonaws.com" }, "eventTime": "2018-10-17T18:15:11Z", "eventSource": "greengrass.amazonaws.com", "eventName": "GetGroupVersion", "awsRegion": "us-east-1", "sourceIPAddress": "203.0.113.12", "userAgent": "apimanager.amazonaws.com", "requestParameters": { "GroupVersionId": "6c477753-dbf2-4cb8-acc3-5ba4eEXAMPLE", "GroupId": "90fcf6df-413c-4515-93a8-00056EXAMPLE" }, "responseElements": null, "requestID": "95dcffce-d238-11e8-9240-a3993EXAMPLE", "eventID": "8a608034-82ed-431b-b5e0-87fbdEXAMPLE", "readOnly": true, "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

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

{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::123456789012:user/Mary_Major", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major" }, "eventTime": "2018-10-17T17:02:12Z", "eventSource": "greengrass.amazonaws.com", "eventName": "GetConnectivityInfo", "awsRegion": "us-east-1", "sourceIPAddress": "203.0.113.12", "userAgent": "apimanager.amazonaws.com", "requestParameters": { "ThingName": "us-east-1_CIS_1539795000000_" }, "responseElements": null, "requestID": "63e3ebe3-d22e-11e8-9ddd-5baf3EXAMPLE", "eventID": "db2260d1-a8cc-4a65-b92a-13f65EXAMPLE", "readOnly": true, "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

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

{ "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::123456789012:user/Mary_Major", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major" }, "eventTime": "2018-10-17T18:01:11Z", "eventSource": "greengrass.amazonaws.com", "eventName": "CreateFunctionDefinition", "awsRegion": "us-east-1", "sourceIPAddress": "203.0.113.12", "userAgent": "apimanager.amazonaws.com", "requestParameters": { "InitialVersion": "***" }, "responseElements": { "CreationTimestamp": "2018-10-17T18:01:11.449Z", "LatestVersion": "dae06a61-c32c-41e9-b983-ee5cfEXAMPLE", "LatestVersionArn": "arn:aws:greengrass:us-east-1:123456789012:/greengrass/definition/functions/7a94847d-d4d2-406c-9796-a3529EXAMPLE/versions/dae06a61-c32c-41e9-b983-ee5cfEXAMPLE", "LastUpdatedTimestamp": "2018-10-17T18:01:11.449Z", "Id": "7a94847d-d4d2-406c-9796-a3529EXAMPLE", "Arn": "arn:aws:greengrass:us-east-1:123456789012:/greengrass/definition/functions/7a94847d-d4d2-406c-9796-a3529EXAMPLE" }, "requestID": "a17d4b96-d236-11e8-a74e-3db27EXAMPLE", "eventID": "bdbf6677-a47a-4c78-b227-c5f64EXAMPLE", "readOnly": false, "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

See also