

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

# 使用记录 AWS AppConfig API 调用 AWS CloudTrail
<a name="logging-using-cloudtrail"></a>

AWS AppConfig 与[AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)一项服务集成，该服务提供用户、角色或角色所执行操作的记录 AWS 服务。 CloudTrail 将所有 API 调用捕获 AWS AppConfig 为事件。捕获的调用包括来自 AWS AppConfig 控制台的调用和对 AWS AppConfig API 操作的代码调用。使用收集的信息 CloudTrail，您可以确定向哪个请求发出 AWS AppConfig、发出请求的 IP 地址、发出请求的时间以及其他详细信息。

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

CloudTrail 在您创建账户 AWS 账户 时在您的账户中处于活动状态，并且您自动可以访问 CloudTrail **活动历史记录**。 CloudTrail **事件历史记录**提供了过去 90 天中记录的管理事件的可查看、可搜索、可下载且不可变的记录。 AWS 区域有关更多信息，请参阅《*AWS CloudTrail 用户指南》*中的 “[使用 CloudTrail 事件历史记录](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)”。查看**活动历史记录**不 CloudTrail收取任何费用。

要持续记录 AWS 账户 过去 90 天内的事件，请创建跟踪或 [CloudTrailLake](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-lake.html) 事件数据存储。

**CloudTrail 步道**  
*跟踪*允许 CloudTrail 将日志文件传输到 Amazon S3 存储桶。使用创建的所有跟踪 AWS 管理控制台 都是多区域的。您可以通过使用 AWS CLI创建单区域或多区域跟踪。建议创建多区域跟踪，因为您可以捕获账户 AWS 区域 中的所有活动。如果您创建单区域跟踪，则只能查看跟踪的 AWS 区域中记录的事件。有关跟踪的更多信息，请参阅《AWS CloudTrail 用户指南》**中的[为您的 AWS 账户创建跟踪](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)和[为组织创建跟踪](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-trail-organization.html)。  
通过创建跟踪，您可以免费将正在进行的管理事件的一份副本传送到您的 Amazon S3 存储桶，但会收取 Amazon S3 存储费用。 CloudTrail 有关 CloudTrail 定价的更多信息，请参阅[AWS CloudTrail 定价](https://aws.amazon.com/cloudtrail/pricing/)。有关 Amazon S3 定价的信息，请参阅 [Amazon S3 定价](https://aws.amazon.com/s3/pricing/)。

**CloudTrail 湖泊事件数据存储**  
CloudTrail L@@ *ak* e 允许你对自己的事件运行基于 SQL 的查询。 CloudTrail Lake 将基于行的 JSON 格式的现有事件转换为 [Apache ORC](https://orc.apache.org/) 格式。ORC 是一种针对快速检索数据进行优化的列式存储格式。事件将被聚合到*事件数据存储*中，它是基于您通过应用[高级事件选择器](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-lake-concepts.html#adv-event-selectors)选择的条件的不可变的事件集合。应用于事件数据存储的选择器用于控制哪些事件持续存在并可供您查询。有关 CloudTrail Lake 的更多信息，[请参阅*AWS CloudTrail 用户指南*中的使用 AWS CloudTrail Lake](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-lake.html)。  
CloudTrail 湖泊事件数据存储和查询会产生费用。创建事件数据存储时，您可以选择要用于事件数据存储的[定价选项](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-lake-manage-costs.html#cloudtrail-lake-manage-costs-pricing-option)。定价选项决定了摄取和存储事件的成本，以及事件数据存储的默认和最长保留期。有关 CloudTrail 定价的更多信息，请参阅[AWS CloudTrail 定价](https://aws.amazon.com/cloudtrail/pricing/)。

## AWS AppConfig 中的数据事件 CloudTrail
<a name="cloudtrail-data-events"></a>

[数据事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events)提供有关在资源上或在资源中执行的资源操作的信息（例如，通过调用检索最新部署的配置 GetLatestConfiguration）。这些也称为数据面板操作。数据事件通常是高容量活动。默认情况下， CloudTrail 不记录数据事件。 CloudTrail **事件历史**记录不记录数据事件。

记录数据事件将收取额外费用。有关 CloudTrail 定价的更多信息，请参阅[AWS CloudTrail 定价](https://aws.amazon.com/cloudtrail/pricing/)。

您可以使用 CloudTrail 控制台或 CloudTrail API 操作记录 AWS AppConfig 资源类型的数据事件。 AWS CLI本节中的[表格](#data-events-table)显示了可用的资源类型 AWS AppConfig。
+ 要使用 CloudTrail 控制台记录数据事件，请创建[跟踪](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html#creating-a-trail-in-the-console)或[事件数据存储](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/query-event-data-store-cloudtrail.html)以记录数据事件，或者[更新现有的跟踪或事件数据存储](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-console)以记录数据事件。

  1. 选择**数据事件**来记录数据事件。

  1. 从**数据事件类型**列表中，选择 **AWS AppConfig**。

  1. 选择要使用的记录选择器模板。可以记录资源类型的所有数据事件、记录所有 `readOnly` 事件、记录所有 `writeOnly` 事件，或者创建自定义记录选择器模板来根据 `readOnly`、`eventName` 和 `resources.ARN` 字段进行筛选。

  1. 在 “**选择器名称**” 中，输入**AppConfigDataEvents**。有关为数据事件跟踪启用 A CloudWatch mazon Logs 的信息，请参阅[记录 AWS AppConfig 数据平面调用的指标](monitoring-data-plane-call-logging.md)。
+ 要使用记录数据事件 AWS CLI，请将`--advanced-event-selectors`参数配置为将`eventCategory`字段设置为等于`Data`并将该`resources.type`字段设置为资源类型值（参见[表](#data-events-table)）。可以添加条件来根据 `readOnly`、`eventName` 和 `resources.ARN` 字段的值进行筛选。
  + 要将跟踪配置为记录数据事件，请运行 [https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/put-event-selectors.html](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/put-event-selectors.html) 命令。有关更多信息，请参阅[使用 AWS CLI记录跟踪的数据事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-CLI-trail-examples)。
  + 要将事件数据存储配置为记录数据事件，请运行 [https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/create-event-data-store.html](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/create-event-data-store.html) 命令以创建新的事件数据存储来记录数据事件，或者运行 [https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/update-event-data-store.html](https://docs.aws.amazon.com/cli/latest/reference/cloudtrail/update-event-data-store.html) 命令来更新现有的事件数据存储。有关更多信息，请参阅[使用 AWS CLI记录事件数据存储的数据事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html#logging-data-events-CLI-eds-examples)。

下表列出了 AWS AppConfig 资源类型。**数据事件类型（控制台）**列显示要从控制 CloudTrail 台上的**数据事件类型**列表中选择的值。res **ources.type 值**列显示该`resources.type`值，您将在使用或配置高级事件选择器时指定该值。 AWS CLI CloudTrail APIs“** APIs 记录到的数据 CloudTrail**” 列显示了 CloudTrail针对该资源类型记录的 API 调用。


| 数据事件类型（控制台） | resources.type 值 | 数据 APIs 已记录到 CloudTrail \$1 | 
| --- | --- | --- | 
| AWS AppConfig |  AWS::AppConfig::Configuration  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/appconfig/latest/userguide/logging-using-cloudtrail.html)  | 

\$1可以将高级事件选择器配置为根据 `eventName`、`readOnly` 和 `resources.ARN` 字段进行筛选，从而仅记录那些对您很重要的事件。有关这些字段的更多信息，请参阅[https://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_AdvancedFieldSelector.html](https://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_AdvancedFieldSelector.html)。

## AWS AppConfig 中的管理事件 CloudTrail
<a name="cloudtrail-management-events"></a>

AWS AppConfig 将所有 AWS AppConfig 控制平面操作记录为管理事件。有关 AWS AppConfig 记录到的 AWS AppConfig 控制平面操作的列表 CloudTrail，请参阅 [AWS AppConfig API 参考](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/Welcome.html)。

## AWS AppConfig 事件示例
<a name="cloudtrail-event-examples"></a>

事件代表来自任何来源的单个请求，包括有关所请求的 API 操作、操作的日期和时间、请求参数等的信息。 CloudTrail 日志文件不是公共 API 调用的有序堆栈跟踪，因此事件不会按任何特定顺序出现。

以下示例显示了一个演示该[StartConfigurationSession](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_appconfigdata_StartConfigurationSession.html)操作 CloudTrail 的事件。

```
{
      "eventVersion": "1.09",
      "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDACKCEVSQ6C2EXAMPLE",
        "arn": "arn:aws:iam::123456789012:user/Administrator",
        "accountId": "123456789012",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "sessionContext": {
          "sessionIssuer": {},
          "attributes": {
            "creationDate": "2024-01-11T14:37:02Z",
            "mfaAuthenticated": "false"
          }
        }
      },
      "eventTime": "2024-01-11T14:45:15Z",
      "eventSource": "appconfig.amazonaws.com",
      "eventName": "StartConfigurationSession",
      "awsRegion": "us-east-1",
      "sourceIPAddress": "203.0.113.0",
      "userAgent": "Boto3/1.34.11 md/Botocore#1.34.11 ua/2.0 os/macos#22.6.0 md/arch#x86_64 lang/python#3.11.4 md/pyimpl#CPython cfg/retry-mode#legacy Botocore/1.34.11",
      "requestParameters": {
        "applicationIdentifier": "rrfexample",
        "environmentIdentifier": "mexampleqe0",
        "configurationProfileIdentifier": "3eexampleu1"
      },
      "responseElements": null,
      "requestID": "a1b2c3d4-5678-90ab-cdef-aaaaaEXAMPLE",
      "eventID": "a1b2c3d4-5678-90ab-cdef-bbbbbEXAMPLE",
      "readOnly": false,
      "resources": [
        {
          "accountId": "123456789012",
          "type": "AWS::AppConfig::Configuration",
          "ARN": "arn:aws:appconfig:us-east-1:123456789012:application/rrfexample/environment/mexampleqe0/configuration/3eexampleu1"
        }
      ],
      "eventType": "AwsApiCall",
      "managementEvent": false,
      "recipientAccountId": "123456789012",
      "eventCategory": "Data",
      "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "appconfigdata.us-east-1.amazonaws.com"
      }
    }
```

有关 CloudTrail 录音内容的信息，请参阅《*AWS CloudTrail 用户指南》*中的[CloudTrail录制内容](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-record-contents.html)。