Logging AWS IoT Greengrass API calls with AWS CloudTrail - AWS IoT Greengrass

AWS IoT Greengrass Version 1 entered the extended life phase on June 30, 2023. For more information, see the AWS IoT Greengrass V1 maintenance policy. After this date, AWS IoT Greengrass V1 won't release updates that provide features, enhancements, bug fixes, or security patches. Devices that run on AWS IoT Greengrass V1 won't be disrupted and will continue to operate and to connect to the cloud. We strongly recommend that you migrate to AWS IoT Greengrass Version 2, which adds significant new features and support for additional platforms.

Logging AWS IoT Greengrass API calls with AWS CloudTrail

AWS IoT Greengrass is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in AWS IoT Greengrass. CloudTrail captures all API calls for AWS IoT Greengrass as events. The calls captured include calls from the AWS IoT Greengrass console and code calls to the AWS 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 AWS 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 AWS 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 AWS CloudTrail User Guide.

AWS IoT Greengrass information in CloudTrail

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

For an ongoing record of events in your AWS account, including events for AWS 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 AWS Regions. The trail logs events from all Regions in the AWS partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see the following:

All AWS IoT Greengrass actions are logged by CloudTrail and are documented in the AWS 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 AWS 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 AWS service.

For more information, see the CloudTrail userIdentity element.

Understanding AWS 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