

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用查看事件 AWS CloudTrail 适用于 Lex V2
<a name="logging-using-cloudtrail"></a>

Amazon Lex V2 与 AWS CloudTrail一项服务集成，该服务提供用户、角色或 AWS 服务在 Amazon Lex V2 中采取的操作的记录。 CloudTrail 将 Amazon Lex V2 的 API 调用捕获为事件。被捕获的调用中包括通过 Amazon Lex V2 控制台的调用以及对 Amazon Lex V2 API 操作的代码调用。如果您创建了跟踪，则可以允许将 CloudTrail 事件持续传输到 Amazon S3 存储桶，包括 Amazon Lex V2 的事件。如果您不配置跟踪记录，则仍可在 CloudTrail 控制台的 **Event history**（事件历史记录）中查看最新事件。使用收集的信息 CloudTrail，您可以确定向 Amazon Lex V2 发出的请求、发出请求的 IP 地址、谁提出了请求、何时提出请求以及其他详细信息。

要了解更多信息 CloudTrail，请参阅[AWS CloudTrail 用户指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)。

## Amazon Lex V2 中的信息 CloudTrail
<a name="lex-info-in-cloudtrail"></a>

CloudTrail 在您的 AWS 账户上创建账户时已启用。当 Amazon Lex V2 中发生活动时，该活动会与其他 AWS 服务 CloudTrail事件一起记录在**事件历史**记录中。您可以在亚马逊云科技 账户中查看、搜索和下载最新事件。有关更多信息，请参阅[使用事件历史记录查看 CloudTrail 事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

要持续记录您的 AWS 账户中的事件，包括 Amazon Lex V2 的事件，请创建跟踪。*跟踪*允许 CloudTrail 将日志文件传输到 Amazon S3 存储桶。默认情况下，在控制台中创建跟踪记录时，此跟踪记录应用于所有 AWS 区域。该跟踪记录来自 AWS 分区中所有区域的事件，并将日志文件传送到您指定的 Amazon S3 存储桶。此外，您可以配置其他 AWS 服务，以进一步分析和处理 CloudTrail 日志中收集的事件数据。有关更多信息，请参阅下列内容：
+ [创建跟踪记录概述](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ [CloudTrail 支持的服务和集成](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html)
+ [为 CloudTrail 配置 Amazon SNS 通知](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/configure-sns-notifications-for-cloudtrail.html)
+ [接收来自多个区域的 CloudTrail 日志文件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html)和[接收来自多个账户的 CloudTrail 日志文件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)

Amazon Lex V2 支持记录[模型构建 API V2](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_Operations_Amazon_Lex_Model_Building_V2.html) 中列出的所有操作。

每个事件或日志条目都包含有关生成请求的人员信息。身份信息有助于您确定以下内容：
+ 请求是使用根用户证书还是 AWS Identity and Access Management 的 IAM 用户凭证发出。
+ 请求是使用角色还是联合用户的临时安全凭证发出的。
+ 请求是否由其他亚马逊云科技 服务发出。

有关更多信息，请参阅 [CloudTrail userIdentity 元素](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)。

## 了解 Amazon Lex V2 日志文件条目
<a name="understanding-service-name-entries"></a>

跟踪是一种配置，允许将事件作为日志文件传输到您指定的 Amazon S3 存储桶。 CloudTrail 日志文件包含一个或多个日志条目。事件代表来自任何来源的单个请求，包括有关请求的操作、操作的日期和时间、请求参数等的信息。 CloudTrail 日志文件不是公共 API 调用的有序堆栈跟踪，因此它们不会按任何特定的顺序出现。

以下示例显示了演示该[CreateBotAlias](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_CreateBotAlias.html)操作的 CloudTrail 日志条目。

```
{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "{{ID of caller}}:{{temporary credentials}}",
        "arn": "arn:aws:sts::{{111122223333}}:assumed-role/{{role name}}/{{role ARN}}",
        "accountId": "{{111122223333}}",
        "accessKeyId": "{{AKIAIOSFODNN7EXAMPLE}}",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "{{ID of caller}}",
                "arn": "arn:aws:iam::{{111122223333}}:role/{{role name}}",
                "accountId": "{{111122223333}}",
                "userName": "{{role name}}"
            },
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "{{creation date}}"
            }
        }
    },
    "eventTime": "{{event timestamp}}",
    "eventSource": "lex.amazonaws.com",
    "eventName": "CreateBotAlias",
    "awsRegion": "{{Region}}",
    "sourceIPAddress": "{{192.0.2.0}}",
    "userAgent": "{{user agent}}",
    "requestParameters": {
        "botAliasLocaleSettingsMap": {
            "en_US": {
                "enabled": true
            }
        },
        "botId": "{{bot ID}}",
        "botAliasName": "{{bot aliase name}}",
        "botVersion": "1"
    },
    "responseElements": {
        "botAliasLocaleSettingsMap": {
            "en_US": {
                "enabled": true
            }
        },
        "botAliasId": "{{bot alias ID}}",
        "botAliasName": "{{bot alias name}}",
        "botId": "{{bot ID}}",
        "botVersion": "1",
        "creationDateTime": {{creation timestamp}}
    },
    "requestID": "{{unique request ID}}",
    "eventID": "{{unique event ID}}",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "recipientAccountId": "{{111122223333}}"
}
```