

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

# 监控 Amazon VPC Lattice
<a name="monitoring-overview"></a>

使用本节中的功能监控您的 Amazon VPC Lattice 服务网络、服务、目标组和 VPC 连接。

**Topics**
+ [CloudWatch 亚马逊 VPC Lattice 的指标](monitoring-cloudwatch.md)
+ [Amazon VPC Lattice 的访问日志](monitoring-access-logs.md)
+ [CloudTrail 亚马逊 VPC Lattice 的日志](monitoring-cloudtrail.md)

# CloudWatch 亚马逊 VPC Lattice 的指标
<a name="monitoring-cloudwatch"></a>

Amazon VPC Lattice 将与您的目标群体和服务相关的数据发送到亚马逊 CloudWatch，并将其处理为可读的近乎实时的指标。这些指标会保留 15 个月，使您能够访问历史信息，并更好地了解您的 Web 应用程序或服务的执行情况。此外，可以设置用于监测特定阈值的警报，并在达到相应阈值时发送通知或执行操作。有关更多信息，请参阅 [Amazon CloudWatch 用户指南](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。

Amazon VPC Lattice 使用您 AWS 账户中的服务相关角色向亚马逊发送指标。 CloudWatch有关更多信息，请参阅 [使用适用于 Amazon VPC 莱迪思的服务相关角色](using-service-linked-roles.md)。

**Topics**
+ [查看 Amazon CloudWatch 指标](#monitoring-cloudwatch-view)
+ [目标组指标](#monitoring-cloudwatch-tg)
+ [服务指标](#monitoring-cloudwatch-service)

## 查看 Amazon CloudWatch 指标
<a name="monitoring-cloudwatch-view"></a>

您可以使用 CloudWatch 控制台或查看目标群体和服务的Amazon CloudWatch 指标 AWS CLI。

**使用 CloudWatch 控制台查看指标**

1. 打开 Amazon CloudWatch 控制台，网址为[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/)。

1. 在导航窗格中，选择**指标**。

1. 选择 `AWS/VpcLattice` 命名空间。

1. （可选）要跨所有维度查看某个指标，请在搜索字段中输入其名称。

1. (可选) 要按维度筛选，请选择下列选项之一：
   + 要仅显示为目标组报告的指标，请选择**目标组**。要查看单个目标组的指标，请在搜索字段中输入其名称。
   + 要仅显示为服务报告的指标，请选择**服务**。要查看单个服务的指标，请在搜索字段中输入其名称。

**要查看指标，请使用 AWS CLI**

使用以下 [CloudWatch list-Metrics AWS CLI 命令列出可用指标](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/list-metrics.html)：

`aws cloudwatch list-metrics --namespace AWS/VpcLattice`

有关每个指标及其维度的信息，请参阅 [目标组指标](#monitoring-cloudwatch-tg) 和 [服务指标](#monitoring-cloudwatch-service)。

## 目标组指标
<a name="monitoring-cloudwatch-tg"></a>

VPC Lattice 会自动将与目标群体相关的指标存储在 `AWS/VpcLattice` [Amazon CloudWatch 命名空间](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace)中。有关目标组的更多信息，请参阅 [VPC Lattice 中的目标组](target-groups.md)。

**Dimensions**

要筛选目标群体的指标，请使用以下维度：
+ `AvailabilityZone`
+ `TargetGroup`


| 指标 | 说明 | TargetGroup 协议 | 
| --- | --- | --- | 
|  TotalConnectionCount  |  连接总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  ActiveConnectionCount  |  活动连接数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  ConnectionErrorCount  |  连接失败总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  HTTP1\$1ConnectionCount  |  HTTP/1.1 连接总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  HTTP2\$1ConnectionCount  |  HTTP/2 连接总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  ConnectionTimeoutCount  |  连接的连接超时总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  TotalReceivedConnectionBytes  |  接收的连接字节总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  TotalSentConnectionBytes  |  发送的连接字节总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  TotalRequestCount  |  请求总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  ActiveRequestCount  |  活动请求总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  RequestTime  |  最后一个字节的请求时间（以毫秒为单位）。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  HTTPCode\$12XX\$1Count, HTTPCode\$13XX\$1Count, HTTPCode\$14XX\$1Count, HTTPCode\$15XX\$1Count  |  聚合 HTTP 响应代码。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  TLSConnectionErrorCount  |  TLS 连接错误总数，不包括失败的证书验证。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 
|  TotalTLSConnectionHandshakeCount  |  成功的 TLS 连接握手总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 

## 服务指标
<a name="monitoring-cloudwatch-service"></a>

VPC Lattice 会自动将与服务相关的指标存储在 `AWS/VpcLattice` [Amazon CloudWatch 命名空间](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace)中。有关服务的更多信息，请参阅 [VPC Lattice 中的服务](services.md)。

**Dimensions**

要筛选目标群体的指标，请使用以下维度：
+ `AvailabilityZone`
+ `Service`


| 指标 | 说明 | 
| --- | --- | 
|  RequestTimeoutCount  |  等待响应超时的请求总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 
|  TotalRequestCount  |  请求总数。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 
|  RequestTime  |  请求时间（毫秒）。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 
|  HTTPCode\$12XX\$1Count, HTTPCode\$13XX\$1Count, HTTPCode\$14XX\$1Count, HTTPCode\$15XX\$1Count  |  聚合 HTTP 响应代码。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 

# Amazon VPC Lattice 的访问日志
<a name="monitoring-access-logs"></a>

访问日志会捕获有关您的VPC Lattice服务和资源配置的详细信息。您可以使用这些访问日志来分析流量模式，并审计网络中的所有服务。对于 VPC Lattice 服务，我们发布`VpcLatticeAccessLogs`；对于资源配置，我们发布`VpcLatticeResourceAccessLogs`，需要单独配置。

访问日志是可选的，默认情况下处于禁用状态。启用访问日志后，您可以随时禁用。

**定价**  
发布访问日志时需要付费。以您的名义在 AWS 本地发布的日志称为公开日*志。*有关销售日志定价的更多信息，请参阅 [Amazon CloudWatch 定价](https://aws.amazon.com/cloudwatch/pricing/)，选择日**志**，然后在 **Vended Logs 下查看定价。**

**Topics**
+ [启用访问日志所需的 IAM 权限](#monitoring-access-logs-IAM)
+ [访问日志目标](#monitoring-access-logs-destinations)
+ [启用访问日志](#monitoring-access-logs-enable)
+ [请求追踪](#x-amzn-RequestId-enable)
+ [访问日志内容](#monitoring-access-logs-contents)
+ [资源访问日志内容](#monitoring-resource-access-logs-contents)
+ [访问日志问题排查](#monitoring-access-logs-troubleshoot)

## 启用访问日志所需的 IAM 权限
<a name="monitoring-access-logs-IAM"></a>

要启用访问日志并将日志发送到其目标，必须在策略中将以下操作附加到您正在使用的 IAM 用户、组或角色。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "ManageVPCLatticeAccessLogSetup",
            "Action": [
                "logs:CreateLogDelivery",
                "logs:GetLogDelivery",
                "logs:UpdateLogDelivery",
                "logs:DeleteLogDelivery",
                "logs:ListLogDeliveries",
                "vpc-lattice:CreateAccessLogSubscription",
                "vpc-lattice:GetAccessLogSubscription",
                "vpc-lattice:UpdateAccessLogSubscription",
                "vpc-lattice:DeleteAccessLogSubscription",
                "vpc-lattice:ListAccessLogSubscriptions"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

有关更多信息，请参阅《AWS Identity and Access Management 用户指南**》中的[添加和删除 IAM 标识权限](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

更新附加到您正在使用的 IAM 用户、组或角色的策略后，请转到 [启用访问日志](#monitoring-access-logs-enable)。

## 访问日志目标
<a name="monitoring-access-logs-destinations"></a>

您可以将访问日志发送到以下目标。

**Amazon CloudWatch 日志**
+ VPC Lattice 通常会在 2 分钟内将 CloudWatch 日志传送到日志。但请记住，实际日志传输时间是尽最大努力计算的，可能会有额外的延迟。
+ 如果 CloudWatch 日志组没有特定权限，则会自动创建资源策略并将其添加到日志组中。有关更多信息，请参阅 *Amazon CloudWatch 用户指南*中的[发送到 CloudWatch 日志](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-CWL)的日志。
+ 您可以在 CloudWatch控制台的 “日志组 CloudWatch ” 下找到发送到的访问日志。有关更多信息，请参阅 *Amazon CloudWatch 用户指南*中的[查看发送到 CloudWatch 日志的日志数据](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#ViewingLogData)。

**Amazon S3**
+ VPC Lattice 通常会在 6 分钟内将日志传输到 Amazon S3。但请记住，实际日志传输时间是尽最大努力计算的，可能会有额外的延迟。
+ 如果存储桶没有特定权限，系统将自动创建存储桶策略，并将其添加到您的 Amazon S3 存储桶。有关更多信息，请参阅亚马逊* CloudWatch用户指南中的发送到 Amazon* [S3 的日志](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-S3)。
+ 发送到 Amazon S3 的访问日志使用以下命名约定：

  ```
  [bucket]/[prefix]/AWSLogs/[accountId]/VpcLattice/AccessLogs/[region]/[YYYY/MM/DD]/[resource-id]/[accountId]_VpcLatticeAccessLogs_[region]_[resource-id]_YYYYMMDDTHHmmZ_[hash].json.gz
  ```
+ VpcLatticeResourceAccessLogs 发送到 Amazon S3 的内容使用以下命名约定：

  ```
  [bucket]/[prefix]/AWSLogs/[accountId]/VpcLattice/ResourceAccessLogs/[region]/[YYYY/MM/DD]/[resource-id]/[accountId]_VpcLatticeResourceAccessLogs_[region]_[resource-id]_YYYYMMDDTHHmmZ_[hash].json.gz
  ```

**Amazon Data Firehose**
+ VPC Lattice 通常会在 2 分钟内将日志传送到 Firehose。但请记住，实际日志传输时间是尽最大努力计算的，可能会有额外的延迟。
+ 系统会自动创建一个服务相关角色，该角色授予 VPC Lattice 向 Amazon Data Firehose发送访问日志的权限。为使自动角色创建成功，用户必须具有 `iam:CreateServiceLinkedRole` 操作的权限。有关更多信息，请参阅 *Amazon CloudWatch 用户指南 Amazon Data Firehose*中的[发送到的日志](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-Firehose)。
+ 有关查看发送到 Amazon Data Firehose日志的更多信息，请参阅《Amazon Data Firehose 开发人员指南》**中的[监控 Amazon Kinesis Data Streams](https://docs.aws.amazon.com//streams/latest/dev/monitoring.html)。

## 启用访问日志
<a name="monitoring-access-logs-enable"></a>

完成以下过程，配置访问日志，以捕获访问日志并将其传输到您选择的目标。

**Topics**
+ [使用控制台启用访问日志](#monitoring-access-logs-console)
+ [使用启用访问日志 AWS CLI](#monitoring-access-logs-cli)

### 使用控制台启用访问日志
<a name="monitoring-access-logs-console"></a>

您可以在创建期间启用服务网络、服务或资源配置的访问日志。您还可以在创建服务网络、服务或资源配置后启用访问日志，如以下过程所述。

**要使用控制台创建基本服务**

1. 打开位于 [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/) 的 Amazon VPC 控制台。

1. 选择服务网络、服务或资源配置。

1. 选择**操作**和**编辑日志设置**。

1. 打开**访问日志**切换开关。

1. 为访问日志添加传输目标，如下所示：
   + 选择**CloudWatch 日志组**，然后选择一个日志组。要创建日志组，请选择**在中创建日志组 CloudWatch**。
   + 选择 **S3 存储桶**并输入 S3 存储桶路径，包括任何前缀。要搜索 S3 存储桶，请选择**浏览 S3**。
   + 选择 **Kinesis Data Firehose 传输流**，然后选择一个传输流。要创建传输流，请选择**在 Kinesis 中创建传输流**。

1. 选择**保存更改**。

### 使用启用访问日志 AWS CLI
<a name="monitoring-access-logs-cli"></a>

使用 CLI 命令[create-access-log-subscription](https://docs.aws.amazon.com/cli/latest/reference/vpc-lattice/create-access-log-subscription.html)启用服务网络或服务的访问日志。

## 请求追踪
<a name="x-amzn-RequestId-enable"></a>

 VPC Lattice 支持跨客户端、目标和日志的请求跟踪和关联，以实现可观察性和使用标头进行调试。 x-amzn-requestid此标头可以由客户端设置和发送，也可以由VPC Lattice生成，发送到目标，也可以在访问日志中找到。

**默认 行为**
+ VPC Lattice 会为每个请求自动生成此标头。
+ 该值是随机生成的标识符（默认为 UUID 样式）。
+ 生成的标识符是：
  + 已传播到下游目标。
  +  在客户端的响应标头中返回。
  + 登录访问日志

**示例（默认响应）**  
以下是发送给客户端的响应示例，默认行为为 VPC Lattice 为 value eo x-amzn-requestid f 标头生成随机值。

```
{
    "HTTP/1.1 200 OK
    x-amzn-requestid: a9f2c7a1-6b4f-4c79-9e87-ff5a1234a001"
}
```

**客户机设定值**
+ 客户端可以选择在传入的请求上设置此标头，以覆盖自动生成的值。
+ 注意事项
  +  标头值不需要遵循 UUID 格式。
  + 如果标头值超过 512 字节，VPC Lattice 会将其截断为 512 字节。
+  成功重写后，提供的标头值将：
  + 出现在响应标题中
  + 传播到目标
  + 出现在访问日志和指标中

**示例（覆盖客户端请求）**  
以下是客户端发送的带有标头值的请求的示例。

```
{
    "GET /my-service/endpoint HTTP/1.1 
    Host: my-api.example.com
    x-amzn-requestid: trace-request-foobar"
}
```

**示例（默认覆盖响应）**  
以下是向客户端发送的带有被覆盖值的响应的示例。

```
{
    "HTTP/1.1 200 OK
    x-amzn-requestid: trace-request-foobar"
}
```

## 访问日志内容
<a name="monitoring-access-logs-contents"></a>

下表描述了访问日志条目的字段。


| 字段 | 说明 | Format | 
| --- | --- | --- | 
|  callerPrincipalTags  |  请求 PrincipalTags 中的。  | JSON | 
|  hostHeader  |  请求的授权标头。  |  字符串  | 
|  sslCipher  |  用于建立客户端 TLS 连接的一组密码的 OpenSSL 名称。  |  字符串  | 
|  serviceNetworkArn  |  服务网络 ARN。  |  arn: aws: vpc-lattice::: servicenetwork/ *region* *account* *id*  | 
|  resolvedUser  |  启用并完成验证后用户的 ARN。  |  null \$1 ARN \$1 "Anonymous" \$1 "Unknown"  | 
|  authDeniedReason  |  启用验证后访问被拒绝的原因。  |  null \$1 "Service" \$1 "Network" \$1 "Identity"  | 
|  requestMethod  |  请求的方法标头。  |  字符串  | 
|  targetGroupArn  |  目标主机所属的目标主机组。  |  字符串  | 
|  tlsVersion  |  TLS 版本。  |  TLSv*x*  | 
|  userAgent  |  用户代理标头。  |  字符串  | 
|  serverNameIndication  |  [仅限 HTTPS]在服务器名称指示（SNI）的 ssl 连接套接字上设置的值。  |  字符串  | 
|  destinationVpcId  |  目标 VPC ID。  |  vpc-*xxxxxxxx*  | 
|  sourceIpPort  |  源的 IP 地址和端口。  |  *ip*:*port*  | 
|  targetIpPort  |  目标的 IP 地址和端口。  |  *ip*:*port*  | 
|  serviceArn  |  服务 ARN。  |  arn: aws: vpc-lattice::: service/ *region* *account* *id*  | 
|  sourceVpcId  |  源 VPC ID。  |  vpc-*xxxxxxxx*  | 
|  requestPath  |  请求的路径。  |  LatticePath?:*path*  | 
|  startTime  |  请求开始时间。  |  *YYYY*-*MM*-*DD* T*HH*:*MM*: *SS* Z  | 
|  protocol  |  协议。目前是 HTTP/1.1 或 HTTP/2。  |  字符串  | 
|  responseCode  |  HTTP 响应代码。仅记录最终标头的响应代码。有关更多信息，请参阅 [访问日志问题排查](#monitoring-access-logs-troubleshoot)。  |  整数  | 
|  bytesReceived  |  收到的正文和标头字节。  |  整数  | 
|  bytesSent  |  发送的正文和标头字节。  |  整数  | 
|  duration  |  请求从开始时间到最后一个字节输出的总持续时间（毫秒）。  |  整数  | 
|  requestToTargetDuration  |  请求从开始时间到发送到目标的最后一个字节的总持续时间（毫秒）。  |  整数  | 
|  responseFromTargetDuration  |  请求从目标主机读取第一个字节到发送到客户端的最后一个字节的总持续时间（毫秒）。  |  整数  | 
|  grpcResponseCode  |  gRPC 响应代码。有关更多信息，请参阅[状态代码及其在 gRPC 中的使用](https://grpc.github.io/grpc/core/md_doc_statuscodes.html)。仅当服务支持 gRPC 时，才会记录此字段。  |  整数  | 
|  requestId  |  这是一个唯一标识符，作为标 x-amzn-requestid题的值自动包含在响应中。它支持跨客户端、目标和日志的请求关联，以实现可观察性和调试。  |  字符串  | 
|  callerPrincipal  |  经过验证的主体。  |  字符串  | 
|  callerX509SubjectCN  |  使用者名称（CN）。  |  字符串  | 
|  callerX509IssuerOU  |  发布者（OU）。  |  字符串  | 
|  callerX509SANNameCN  |  发布者备用名称（名称/CN）。  |  字符串  | 
|  callerX509SANDNS  |  使用者备用名称（DNS）。  |  字符串  | 
|  callerX509SANURI  |  使用者备用名称（URI）。  |  字符串  | 
|  sourceVpcArn  |  发出请求的 VPC 的 ARN。  |  arn: aws: ec2::: vpc/ *region* *account* *id*  | 
| failureReason | 指明请求失败的原因。可能的值包括： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-access-logs.html) | 字符串 | 

**示例**  
以下是示例日志条目。

```
{
    "callerPrincipalTags" : "{ "TagA": "ValA", "TagB": "ValB", ... }",
    "hostHeader": "example.com",
    "sslCipher": "-",
    "serviceNetworkArn": "arn:aws:vpc-lattice:us-west-2:123456789012:servicenetwork/svn-1a2b3c4d",
    "resolvedUser": "Unknown",
    "authDeniedReason": "null",
    "requestMethod": "GET",
    "targetGroupArn": "arn:aws:vpc-lattice:us-west-2:123456789012:targetgroup/tg-1a2b3c4d",
    "tlsVersion": "-",
    "userAgent": "-",
    "serverNameIndication": "-",
    "destinationVpcId": "vpc-0abcdef1234567890",
    "sourceIpPort": "178.0.181.150:80",
    "targetIpPort": "131.31.44.176:80",
    "serviceArn": "arn:aws:vpc-lattice:us-west-2:123456789012:service/svc-1a2b3c4d",
    "sourceVpcId": "vpc-0abcdef1234567890",
    "requestPath": "/billing",
    "startTime": "2023-07-28T20:48:45Z",
    "protocol": "HTTP/1.1",
    "responseCode": 200,
    "bytesReceived": 42,
    "bytesSent": 42,
    "duration": 375,
    "requestToTargetDuration": 1,
    "responseFromTargetDuration": 1,
    "grpcResponseCode": 1,
    "requestId": "a9f2c7a1-6b4f-4c79-9e87-ff5a1234a001"
}
```

## 资源访问日志内容
<a name="monitoring-resource-access-logs-contents"></a>

下表描述了资源访问日志条目的字段。


| 字段 | 说明 | Format | 
| --- | --- | --- | 
|  serviceNetworkArn  |  服务网络 ARN。  |  arn: *partition* vpc-lattice::: servicenetwork/ *region* *account* *id*  | 
|  serviceNetworkResourceAssociationId  |  服务网络资源 ID。  |  *snra*-*xxx*  | 
|  vpcEndpointId  |  用于访问资源的终端节点 ID。  |  字符串  | 
|  sourceVpcArn  |  源 VPC ARN 或从中发起连接的 VPC。  |  字符串  | 
|  resourceConfigurationArn  |  被访问的资源配置的 ARN。  |  字符串  | 
|  protocol  |  用于与资源配置通信的协议。目前仅支持 tcp。  |  字符串  | 
|  sourceIpPort  |  发起连接的源的 IP 地址和端口。  |  *ip*:*port*  | 
|  destinationIpPort  |  发起连接时使用的 IP 地址和端口。这将是 SN-E/SN-A 的 IP。  |  *ip*:*port*  | 
|  gatewayIpPort  |  资源网关用于访问资源的 IP 地址和端口。  |  *ip*:*port*  | 
|  resourceIpPort  |  资源的 IP 地址和端口。  |  *ip*:*port*  | 

**示例**  
以下是示例日志条目。

```
{
    "eventTimestamp": "2024-12-02T10:10:10.123Z",
    "serviceNetworkArn": "arn:aws:vpc-lattice:us-west-2:1234567890:servicenetwork/sn-1a2b3c4d",
    "serviceNetworkResourceAssociationId": "snra-1a2b3c4d",
    "vpcEndpointId": "vpce-01a2b3c4d",
    "sourceVpcArn": "arn:aws:ec2:us-west-2:1234567890:vpc/vpc-01a2b3c4d",
    "resourceConfigurationArn": "arn:aws:vpc-lattice:us-west-2:0987654321:resourceconfiguration/rcfg-01a2b3c4d",
    "protocol": "tcp",
    "sourceIpPort": "172.31.23.56:44076",
    "destinationIpPort": "172.31.31.226:80",
    "gatewayIpPort": "10.0.28.57:49288",
    "resourceIpPort": "10.0.18.190:80"
}
```

## 访问日志问题排查
<a name="monitoring-access-logs-troubleshoot"></a>

本章节包含您可能在访问日志中看到的 HTTP 错误代码的解释。


| 错误代码 | 可能的原因 | 
| --- | --- | 
|  HTTP 400：错误请求  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/vpc-lattice/latest/ug/monitoring-access-logs.html)  | 
|  HTTP 403：禁止访问  |  已为服务配置验证，但传入请求未经过验证或授权。  | 
|  HTTP 404：服务不存在  |  您正在尝试连接到不存在或未注册到正确服务网络的服务。  | 
|  HTTP 500：内部服务器错误  |  VPC Lattice 遇到错误，例如无法连接到目标。  | 
|  HTTP 502：无效网关  |  VPC Lattice 遇到错误。  | 

# CloudTrail 亚马逊 VPC Lattice 的日志
<a name="monitoring-cloudtrail"></a>

Amazon VPC Lattice 与[AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)一项服务集成，该服务提供用户、角色或角色所执行操作的 AWS 服务记录。 CloudTrail 将 VPC Lattice 的所有 API 调用捕获为事件。捕获的调用包括来自VPC莱迪思控制台的调用和对VPC Lattice API操作的代码调用。通过收集的信息 CloudTrail，您可以确定向 VPC Lattice 发出的请求、发出请求的 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/)。

要监控其他操作，请使用访问日志。有关更多信息，请参阅 [访问日志](monitoring-access-logs.md)。

## VPC 莱迪思管理事件位于 CloudTrail
<a name="cloudtrail-management-events"></a>

[管理事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-management-events-with-cloudtrail.html#logging-management-events)提供有关对中的资源执行的管理操作的信息 AWS 账户。这些也称为控制面板操作。默认情况下， CloudTrail 记录管理事件。

Amazon VPC Lattice 将 VPC 莱迪思控制平面操作记录为管理事件。有关 VPC Lattice 记录的 Amazon VPC Lattice 控制平面操作列表 CloudTrail，请参阅亚马逊 [VPC Lattice](https://docs.aws.amazon.com/vpc-lattice/latest/APIReference/) API 参考。

## VPC 莱迪思事件示例
<a name="cloudtrail-event-examples"></a>

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

以下示例显示了该[CreateService](https://docs.aws.amazon.com/vpc-lattice/latest/APIReference/API_CreateService.html)操作 CloudTrail 的事件。

```
{
  "eventVersion": "1.08",
  "userIdentity": {
    "type": "AssumedRole",
    "principalId": "abcdef01234567890",
    "arn": "arn:abcdef01234567890",
    "accountId": "abcdef01234567890",
    "accessKeyId": "abcdef01234567890",
    "sessionContext": {
        "sessionIssuer": {
            "type": "Role",
            "principalId": "abcdef01234567890",
            "arn": "arn:abcdef01234567890",
            "accountId": "abcdef01234567890",
            "userName": "abcdef01234567890"
        },
        "webIdFederationData": {},
        "attributes": {
            "creationDate": "2022-08-16T03:34:54Z",
            "mfaAuthenticated": "false"
        }
    }
  },
  "eventTime": "2022-08-16T03:36:12Z",
  "eventSource": "vpc-lattice.amazonaws.com",
  "eventName": "CreateService",
  "awsRegion": "us-west-2",
  "sourceIPAddress": "abcdef01234567890",
  "userAgent": "abcdef01234567890",
  "requestParameters": {
    "name": "rates-service"
  },
  "responseElements": {
    "name": "rates-service",
    "id": "abcdef01234567890",
    "arn": "arn:abcdef01234567890",
    "status": "CREATE_IN_PROGRESS"
  },
  "requestID": "abcdef01234567890",
  "eventID": "abcdef01234567890",
  "readOnly": false,
  "eventType": "AwsApiCall",
  "managementEvent": true,
  "recipientAccountId": "abcdef01234567890",
  "eventCategory": "Management"
}
```

以下示例显示了该[DeleteService](https://docs.aws.amazon.com/vpc-lattice/latest/APIReference/API_DeleteService.html)操作 CloudTrail 的事件。

```
{
  "eventVersion": "1.08",
  "userIdentity": {
    "type": "AssumedRole",
    "principalId": "abcdef01234567890",
    "arn": "arn:ABCXYZ123456",
    "accountId": "abcdef01234567890",
    "accessKeyId": "abcdef01234567890",
    "sessionContext": {
        "sessionIssuer": {
            "type": "Role",
            "principalId": "abcdef01234567890",
            "arn": "arn:aws:iam::AIDACKCEVSQ6C2EXAMPLE:role/Admin",
            "accountId": "abcdef01234567890",
            "userName": "Admin"
        },
        "webIdFederationData": {},
        "attributes": {
            "creationDate": "2022-10-27T17:42:36Z",
            "mfaAuthenticated": "false"
        }
    }
  },
  "eventTime": "2022-10-27T17:56:41Z",
  "eventSource": "vpc-lattice.amazonaws.com",
  "eventName": "DeleteService",
  "awsRegion": "us-east-1",
  "sourceIPAddress": "72.21.198.64",
  "userAgent": "abcdef01234567890",
  "requestParameters": {
    "serviceIdentifier": "abcdef01234567890"
  },
  "responseElements": {
    "name": "test",
    "id": "abcdef01234567890",
    "arn": "arn:abcdef01234567890",
    "status": "DELETE_IN_PROGRESS"
  },
  "requestID": "abcdef01234567890",
  "eventID": "abcdef01234567890",
  "readOnly": false,
  "eventType": "AwsApiCall",
  "managementEvent": true,
  "recipientAccountId": "abcdef01234567890",
  "eventCategory": "Management"       
}
```

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