

# 使用 AWS CloudTrail 对 S3 Vectors 进行日志记录
<a name="s3-vectors-logging"></a>

Amazon S3 Vectors 与 AWS CloudTrail 集成，后一项服务提供由用户、角色或 AWS 服务采取的操作的记录。CloudTrail 将 S3 Vectors 的所有 API 调用作为事件捕获。借助通过 CloudTrail 收集的信息，可以确定向 S3 Vectors 发出了哪些请求、从中发出请求的 IP 地址、发出请求的时间以及其它详细信息。当 S3 Vectors 中发生受支持的事件活动时，该活动将记录在 CloudTrail 事件中。可以使用 CloudTrail 跟踪记录来记录 S3 Vectors 的管理事件和数据事件。

要了解有关 CloudTrail 的更多信息，请参阅[《CloudTrail 用户指南》](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

## CloudTrail 中的 S3 Vectors 信息
<a name="s3-vectors-logging-information"></a>

在您创建 AWS 账户时，将在该账户上启用 CloudTrail。当 S3 Vectors 中发生活动时，该活动将记录在 CloudTrail 事件中，并与其它 AWS 服务事件一同保存在事件历史记录中。您可以在 AWS 账户中查看、搜索和下载最新事件。有关更多信息，请参阅[使用 CloudTrail 事件历史记录查看事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

要持续记录 AWS 账户中的事件（包括 S3 Vectors 的事件），请创建跟踪记录。通过跟踪，CloudTrail 可将日志文件传送至 Amazon S3 存储桶。预设情况下，在控制台中创建跟踪时，此跟踪应用于所有 AWS 区域。此跟踪记录在 AWS 分区中记录所有区域中的事件，并将日志文件传送至您指定的 Amazon S3 存储桶。此外，您可以配置其他 AWS 服务，进一步分析在 CloudTrail 日志中收集的事件数据并采取行动。有关更多信息，请参阅《CloudTrail User Guide》**中的 [Overview for Creating a Trail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)、[Configuring Amazon SNS Notifications for CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/getting-notifications-top-level.html)、[Receiving CloudTrail Log Files from Multiple Regions](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html) 和 [Receiving CloudTrail Log Files from Multiple Accounts](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)。

所有 S3 Vectors API 操作均由 CloudTrail 记录下来并记载到 [Amazon S3 Vectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations_Amazon_S3_Vectors.html) API 参考中。例如，对 [CreateVectorBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_CreateVectorBucket.html)、[CreateIndex](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_CreateIndex.html) 和 [QueryVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_QueryVectors.html) 操作的调用会在 CloudTrail 日志文件中生成条目。

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

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

## S3 Vectors 的 CloudTrail 管理事件
<a name="s3-vectors-logging-management-events"></a>

管理事件提供对您 AWS 账户内的资源所执行管理操作的相关信息。这些也称为控制面板操作。默认情况下，CloudTrail 会记录管理事件。

对于 S3 Vectors，CloudTrail 记录以下管理事件：
+ [CreateVectorBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_CreateVectorBucket.html)
+ [DeleteVectorBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_DeleteVectorBucket.html)
+ [GetVectorBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_GetVectorBucket.html)
+ [ListVectorBuckets](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_ListVectorBuckets.html)
+ [PutVectorBucketPolicy](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_PutVectorBucketPolicy.html)
+ [GetVectorBucketPolicy](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_GetVectorBucketPolicy.html)
+ [DeleteVectorBucketPolicy](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_DeleteVectorBucketPolicy.html)
+ [CreateIndex](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_CreateIndex.html)
+ [DeleteIndex](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_DeleteIndex.html)
+ [GetIndex](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_GetIndex.html)
+ [ListIndexes](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_ListIndexes.html)

S3 Vectors 管理事件和数据事件的 `eventSource` 为 `s3vectors.amazonaws.com`。

有关管理事件的更多信息，请参阅《CloudTrail User Guide》**中的 [Logging management events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-management-events-with-cloudtrail.html)。

## S3 Vectors 的 CloudTrail 数据事件
<a name="s3-vectors-logging-data-events"></a>

数据事件提供有关对在资源上或资源内执行的资源操作的信息。这些也称为数据面板操作。默认情况下，CloudTrail 不记录数据事件。但是，可以将跟踪记录配置为记录 S3 Vectors 资源的数据事件。

当您将跟踪记录配置为记录数据事件时，可以指定 S3 Vectors 资源类型。S3 Vectors 对于数据事件支持以下资源类型：
+ `AWS::S3Vectors::VectorBucket`：记录指定向量存储桶中所有向量索引的数据事件
+ `AWS::S3Vectors::Index`：记录特定向量索引的数据事件

对于 S3 Vectors，CloudTrail 记录以下数据事件：

向量数据操作：
+ [PutVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_PutVectors.html)：当将向量添加到向量索引时进行记录
+ [GetVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_GetVectors.html)：当从向量索引中检索向量时进行记录
+ [DeleteVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_DeleteVectors.html)：当从向量索引中删除向量时进行记录
+ [ListVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_ListVectors.html)：当列出向量索引中的向量时进行记录
+ [QueryVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_QueryVectors.html)：当对向量索引执行相似性查询时进行记录

S3 Vectors 数据事件的 `eventSource` 为 `s3vectors.amazonaws.com`。

## 为 S3 Vectors 启用数据事件日志记录
<a name="s3-vectors-logging-enabling-data-events"></a>

在创建或更新 CloudTrail 跟踪记录时，可以为 S3 Vectors 资源启用数据事件日志记录。可以为您账户中的所有向量存储桶和向量索引指定日志记录，也可以指定各个向量存储桶或向量索引。有关创建跟踪记录的详细步骤，请参阅《CloudTrail User Guide》**中的 [Creating a trail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html)。

要为所有 S3 Vectors 资源启用数据事件日志记录：
+ 创建或更新跟踪记录时，选择**数据事件**。
+ 对于**资源类型**，选择 `AWS::S3Vectors::VectorBucket`。
+ 对于**资源 ARN**，输入 `arn:aws:s3vectors:_:_:bucket/*` 以记录所有向量存储桶的事件，或者指定各个向量存储桶 ARN（例如 `arn:aws:s3vectors:us-east-1:123456789012:bucket/amzn-s3-demo-vector-bucket`）。

要为特定向量索引启用数据事件日志记录：
+ 创建或更新跟踪记录时，选择**数据事件**。
+ 对于**资源类型**，选择 `AWS::S3Vectors::Index`。
+ 对于**资源 ARN**，输入特定向量索引的 ARN，例如：`arn:aws:s3vectors:us-east-1:123456789012:bucket/amzn-s3-demo-vector-bucket/index/my-index`。

有关数据事件的更多信息，请参阅《CloudTrail User Guide》**中的 [Logging data events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html)。

**Topics**
+ [CloudTrail 中的 S3 Vectors 信息](#s3-vectors-logging-information)
+ [S3 Vectors 的 CloudTrail 管理事件](#s3-vectors-logging-management-events)
+ [S3 Vectors 的 CloudTrail 数据事件](#s3-vectors-logging-data-events)
+ [为 S3 Vectors 启用数据事件日志记录](#s3-vectors-logging-enabling-data-events)
+ [S3 Vectors 的 CloudTrail 日志文件示例](s3-vectors-cloudtrail-log-example.md)

# S3 Vectors 的 CloudTrail 日志文件示例
<a name="s3-vectors-cloudtrail-log-example"></a>

以下示例显示 S3 Vectors 数据事件的 CloudTrail 日志条目。对向量索引中的向量数据执行操作时，会记录数据事件。

## 示例：`GetVectors` 数据事件的 CloudTrail 日志文件
<a name="s3-vectors-cloudtrail-getvectors-example"></a>

```
{
    "eventVersion": "1.11",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "123456789012",
        "arn": "arn:aws:iam::123456789012:user/myUserName",
        "accountId": "123456789012",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "userName": "myUserName"
    },
    "eventTime": "2024-11-22T17:12:25Z",
    "eventSource": "s3vectors.amazonaws.com",
    "eventName": "GetVectors",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "192.0.2.0",
    "userAgent": "[aws-cli/2.18.5]",
    "requestParameters": {
        "vectorBucketName": "amzn-s3-demo-vector-bucket",
        "returnMetadata": "false",
        "indexName": "111aa1111-22bb-33cc-44dd-5555eee66ffff",
        "returnData": "false"
    },            
    "responseElements": null,
    "additionalEventData": {
        "SignatureVersion": "SigV4",
        "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256"
    },
    "requestID": "07D681123BD12AED",
    "eventID": "f2b287f3-0df1-1234-a2f4-c4bdfed47657",
    "readOnly": true,
    "resources": [{
        "accountId": "123456789012",
        "type": "AWS::S3Vectors::VectorBucket",
        "ARN": "arn:aws:s3vectors:us-east-1:123456789012:bucket/amzn-s3-demo-vector-bucket"
    }, {
        "accountId": "123456789012",
        "type": "AWS::S3Vectors::Index",
        "ARN": "arn:aws:s3vectors:us-east-1:123456789012:bucket/amzn-s3-demo-vector-bucket/index/111aa1111-22bb-33cc-44dd-5555eee66ffff"
    }],
    "eventType": "AwsApiCall",
    "managementEvent": false,
    "recipientAccountId": "444455556666",
    "eventCategory": "Data",
    "tlsDetails": {
        "tlsVersion": "TLSv1.2",
        "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256",
        "clientProvidedHostHeader": "client-host"
    }
}
```

## 了解 S3 Vectors 日志文件条目
<a name="s3-vectors-cloudtrail-understanding"></a>

CloudTrail 日志文件包含一个或多个记录条目。一个事件表示来自任何源的一个请求，包括有关所请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公有 API 调用的有序堆栈跟踪，因此它们不会按任何特定顺序显示。

S3 Vectors CloudTrail 日志条目包含以下关键元素：
+ **eventSource**：对于 S3 Vectors 事件，始终为 `s3vectors.amazonaws.com`。
+ **eventName**：执行的 S3 Vectors API 操作。
+ **eventCategory**：对于控制面板操作为 `Management`，或对于数据面板操作为 `Data`。
+ **readOnly**：对于读取操作（例如 [GetVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_GetVectors.html)、[QueryVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_QueryVectors.html)、[ListVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_ListVectors.html)）为 `true`；对于写入操作（例如 [PutVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_PutVectors.html)、[DeleteVectors](https://docs.aws.amazon.com/AmazonS3/latest/API/API_S3VectorBuckets_DeleteVectors.html)）为 `false`。
+ **resources**：操作中涉及的 S3 Vectors 资源，包括向量存储桶和向量索引。
+ **requestParameters**：随请求发送的参数。
+ **responseElements**：S3 Vectors 服务返回的响应元素。