Monitoring Amazon Lex API Calls with AWS CloudTrail Logs - Amazon Lex V1

If you are using Amazon Lex V2, refer to the Amazon Lex V2 guide instead.

 

If you are using Amazon Lex V1, we recommend upgrading your bots to Amazon Lex V2. We are no longer adding new features to V1 and strongly recommend using V2 for all new bots.

Monitoring Amazon Lex API Calls with AWS CloudTrail Logs

Amazon Lex is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in Amazon Lex. CloudTrail captures a subset of API calls for Amazon Lex as events, including calls from the Amazon Lex console and from code calls to the Amazon Lex APIs. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Amazon Lex. 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 Lex, 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, including how to configure and enable it, see the AWS CloudTrail User Guide.

Amazon Lex Information in CloudTrail

CloudTrail is enabled on your AWS account when you create the account. When supported event activity occurs in Amazon Lex, 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 Amazon Lex, create a trail. A trail enables CloudTrail to deliver log files to an Amazon Simple Storage Service (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 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:

Amazon Lex supports logging the following operations as events in CloudTrail log files:

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

  • Whether the request was made with root or 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.

For information about the Amazon Lex actions that are logged in CloudTrail logs, see Amazon Lex Model Building Service. For example, calls to the PutBot, GetBot, and DeleteBot operations generate entries in the CloudTrail log. The actions documented in Amazon Lex Runtime Service, PostContent and PostText, are not logged.

Example: Amazon Lex Log File Entries

A trail is a configuration that enables delivery of events as log files to an 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 CloudTrail log entry shows the result of a call to the PutBot operation.

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole | FederatedUser | IAMUser | Root | SAMLUser | WebIdentityUser", "principalId": "principal ID", "arn": "ARN", "accountId": "account ID", "accessKeyId": "access key ID", "userName": "user name" }, "eventTime": "timestamp", "eventSource": "lex.amazonaws.com", "eventName": "PutBot", "awsRegion": "region", "sourceIPAddress": "source IP address", "userAgent": "user agent", "requestParameters": { "name": "CloudTrailBot", "intents": [ { "intentVersion": "11", "intentName": "TestCloudTrail" } ], "voiceId": "Salli", "childDirected": false, "locale": "en-US", "idleSessionTTLInSeconds": 500, "processBehavior": "BUILD", "description": "CloudTrail test bot", "clarificationPrompt": { "messages": [ { "contentType": "PlainText", "content": "I didn't understand you. What would you like to do?" } ], "maxAttempts": 2 }, "abortStatement": { "messages": [ { "contentType": "PlainText", "content": "Sorry. I'm not able to assist at this time." } ] } }, "responseElements": { "voiceId": "Salli", "locale": "en-US", "childDirected": false, "abortStatement": { "messages": [ { "contentType": "PlainText", "content": "Sorry. I'm not able to assist at this time." } ] }, "status": "BUILDING", "createdDate": "timestamp", "lastUpdatedDate": "timestamp", "idleSessionTTLInSeconds": 500, "intents": [ { "intentVersion": "11", "intentName": "TestCloudTrail" } ], "clarificationPrompt": { "messages": [ { "contentType": "PlainText", "content": "I didn't understand you. What would you like to do?" } ], "maxAttempts": 2 }, "version": "$LATEST", "description": "CloudTrail test bot", "checksum": "checksum", "name": "CloudTrailBot" }, "requestID": "request ID", "eventID": "event ID", "eventType": "AwsApiCall", "recipientAccountId": "account ID" } }