

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

使用本節中的功能來監控 Amazon VPC Lattice 服務網路、服務、目標群組和 VPC 連線。

**Topics**
+ [Amazon VPC Lattice 的 CloudWatch 指標](monitoring-cloudwatch.md)
+ [Amazon VPC Lattice 的存取日誌](monitoring-access-logs.md)
+ [Amazon VPC Lattice 的 CloudTrail 日誌](monitoring-cloudtrail.md)

# Amazon VPC Lattice 的 CloudWatch 指標
<a name="monitoring-cloudwatch"></a>

Amazon VPC Lattice 會將與目標群組和服務相關的資料傳送至 Amazon CloudWatch，並將其處理為可讀且幾近即時的指標。這些指標會保留 15 個月，讓您可以存取歷史資訊，並更清楚 Web 應用程式或服務的效能。您也可以設定警報監看特定閾值，在達到閾值發出通知或採取動作。如需更多資訊，請參閱 [Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。

Amazon VPC Lattice 會在您的帳戶中使用服務連結角色 AWS ，將指標傳送至 Amazon CloudWatch。如需詳細資訊，請參閱[使用 Amazon VPC Lattice 的服務連結角色](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>

您可以使用 Amazon CloudWatch CloudWatch 指標 AWS CLI。

**使用 CloudWatch 主控台檢視指標**

1. 在 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 Amazon CloudWatch 主控台。

1. 在導覽窗格中，選擇 **指標**。

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

1. (選用) 若要檢視所有維度的指標，請在搜尋欄位中輸入其名稱。

1. (選用) 若要根據維度來篩選，請選取下列其中一項：
   + 若要僅顯示目標群組報告的指標，請選擇**目標群組**。若要檢視單一目標群組的指標，請在搜尋欄位中輸入其名稱。
   + 若要僅顯示針對您的服務報告的指標，請選擇**服務**。若要檢視單一服務的指標，請在搜尋欄位中輸入其名稱。

**使用 檢視指標 AWS CLI**

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

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

如需每個指標及其維度的資訊，請參閱 [目標群組指標](#monitoring-cloudwatch-tg)和 [服務指標](#monitoring-cloudwatch-service)。

## 目標群組指標
<a name="monitoring-cloudwatch-tg"></a>

VPC Lattice 會自動將與目標群組相關的指標存放在 Amazon CloudWatch `AWS/VpcLattice` 命名空間中。 [Amazon CloudWatch ](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace) 如需目標群組的詳細資訊，請參閱 [VPC Lattice 中的目標群組](target-groups.md)。

**維度**

若要篩選目標群組的指標，請使用下列維度：
+ `AvailabilityZone`
+ `TargetGroup`


| 指標 | Description | TargetGroup 通訊協定 | 
| --- | --- | --- | 
|  TotalConnectionCount  |  連線總數。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  ConnectionTimeoutCount  |  連線連線逾時總計。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  ActiveRequestCount  |  作用中請求總數。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS  | 
|  RequestTime  |  請求到最後一個位元組的時間，以毫秒為單位。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  |  HTTP, HTTPS, TCP  | 

## 服務指標
<a name="monitoring-cloudwatch-service"></a>

VPC Lattice 會自動將與服務相關的指標存放在 Amazon CloudWatch `AWS/VpcLattice` 命名空間中。 [Amazon CloudWatch ](https://docs.aws.amazon.com//AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace) 如需 服務的詳細資訊，請參閱 [VPC Lattice 中的服務](services.md)。

**維度**

若要篩選目標群組的指標，請使用下列維度：
+ `AvailabilityZone`
+ `Service`


| 指標 | Description | 
| --- | --- | 
|  RequestTimeoutCount  |  等待回應逾時的請求總數。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 
|  TotalRequestCount  |  請求總數。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html)  | 
|  RequestTime  |  請求時間，以毫秒為單位。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-cloudwatch.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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/)、選擇**日誌**，以及檢視**已終止日誌**下的定價。

**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 Logs**
+ VPC Lattice 通常會在 2 分鐘內將日誌交付至 CloudWatch Logs。不過，請記住，實際日誌交付時間是盡最大努力的，可能會有額外的延遲。
+ 如果日誌群組沒有特定許可，會自動建立資源政策並新增至 CloudWatch 日誌群組。如需詳細資訊，請參閱《Amazon [ CloudWatch 使用者指南》中的傳送至 CloudWatch Logs](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-CWL) 的日誌。 *Amazon CloudWatch *
+ 您可以在 CloudWatch 主控台的日誌群組下找到傳送至 CloudWatch 的存取日誌。如需詳細資訊，請參閱《Amazon [ CloudWatch 使用者指南》中的檢視傳送至 CloudWatch Logs 的日誌資料](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#ViewingLogData)。 *Amazon CloudWatch *

**Amazon S3**
+ VPC Lattice 通常會在 6 分鐘內將日誌交付至 Amazon S3。不過，請記住，實際日誌交付時間是盡最大努力的，可能會有額外的延遲。
+ 如果儲存貯體沒有特定許可，系統會自動建立儲存貯體政策並新增至您的 Amazon S3 儲存貯體。如需詳細資訊，請參閱《[Amazon CloudWatch 使用者指南》中的傳送至 Amazon S3 的日誌](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-S3)。 *Amazon CloudWatch *
+ 傳送至 Amazon S3 的存取日誌使用以下命名慣例：

  ```
  [bucket]/[prefix]/AWSLogs/[accountId]/VpcLattice/AccessLogs/[region]/[YYYY/MM/DD]/[resource-id]/[accountId]_VpcLatticeAccessLogs_[region]_[resource-id]_YYYYMMDDTHHmmZ_[hash].json.gz
  ```
+ 傳送至 Amazon S3 的 VpcLatticeResourceAccessLogs 使用以下命名慣例：

  ```
  [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 Log 群組**，然後選擇日誌群組。若要建立日誌群組，請選擇**在 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 為 x-amzn-requestid 標頭產生隨機值。

```
{
    "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>

下表說明存取日誌項目的欄位。


| 欄位 | Description | 格式 | 
| --- | --- | --- | 
|  callerPrincipalTags  |  請求中的 PrincipalTags。  | JSON | 
|  hostHeader  |  請求的授權標頭。  |  string  | 
|  sslCipher  |  用來建立用戶端 TLS 連線之一組密碼的 OpenSSL 名稱。  |  string  | 
|  serviceNetworkArn  |  服務網路 ARN。  |  arn：aws：vpc-lattice：*region*：*account*：servicenetwork/*id*  | 
|  resolvedUser  |  身分驗證啟用且身分驗證完成時的使用者 ARN。  |  null \$1 ARN \$1 "匿名" \$1 "未知"  | 
|  authDeniedReason  |  啟用身分驗證時拒絕存取的原因。  |  null \$1 "Service" \$1 "Network" \$1 "Identity"  | 
|  requestMethod  |  請求的方法標頭。  |  string  | 
|  targetGroupArn  |  目標主機所屬的目標主機群組。  |  string  | 
|  tlsVersion  |  TLS 版本。  |  TLSv**x  | 
|  userAgent  |  使用者代理程式標頭。  |  string  | 
|  serverNameIndication  |  【僅限 HTTPS】 伺服器名稱指示 (SNI) 在 ssl 連線通訊端上設定的值。  |  string  | 
|  destinationVpcId  |  目的地 VPC ID。  |  vpc-*xxxxxxxx*  | 
|  sourceIpPort  |  來源的 IP 地址和 ：port。  |  *ip*：*port*  | 
|  targetIpPort  |  目標的 IP 地址和連接埠。  |  *ip*：*port*  | 
|  serviceArn  |  服務 ARN。  |  arn：aws：vpc-lattice：*region*：*account*：service/*id*  | 
|  sourceVpcId  |  來源 VPC ID。  |  vpc-*xxxxxxxx*  | 
|  requestPath  |  請求的路徑。  |  LatticePath？：*path*  | 
|  startTime  |  請求開始時間。  |  *YYYY*-*MM*-*DD* T*HH*：*MM*：*SS* Z  | 
|  protocol  |  通訊協定。目前為 HTTP/1.1 或 HTTP/2。  |  string  | 
|  responseCode  |  HTTP 回應代碼。只會記錄最終標頭的回應碼。如需詳細資訊，請參閱[對存取日誌進行故障診斷](#monitoring-access-logs-troubleshoot)。  |  integer  | 
|  bytesReceived  |  收到的內文和標頭位元組。  |  integer  | 
|  bytesSent  |  傳送的內文和標頭位元組。  |  integer  | 
|  duration  |  從開始時間到最後一個位元組輸出的請求總持續時間，以毫秒為單位。  |  integer  | 
|  requestToTargetDuration  |  從開始時間到傳送至目標的最後一個位元組的請求總持續時間，以毫秒為單位。  |  integer  | 
|  responseFromTargetDuration  |  從目標主機讀取的第一個位元組到傳送至用戶端的最後一個位元組的請求總持續時間，以毫秒為單位。  |  integer  | 
|  grpcResponseCode  |  gRPC 回應程式碼。如需詳細資訊，請參閱[狀態碼及其在 gRPC 中的使用](https://grpc.github.io/grpc/core/md_doc_statuscodes.html)方式。只有在服務支援 gRPC 時，才會記錄此欄位。  |  integer  | 
|  requestId  |  此唯一識別符會自動包含在回應中，做為 x-amzn-requestid 標頭的值。它可讓用戶端、目標和日誌之間的請求相互關聯，以實現可觀測性和偵錯。  |  string  | 
|  callerPrincipal  |  已驗證的主體。  |  string  | 
|  callerX509SubjectCN  |  主體名稱 (CN)。  |  string  | 
|  callerX509IssuerOU  |  發行者 (OU)。  |  string  | 
|  callerX509SANNameCN  |  發行者替代方案 （名稱/CN)。  |  string  | 
|  callerX509SANDNS  |  主體替代名稱 (DNS)。  |  string  | 
|  callerX509SANURI  |  主體替代名稱 (URI)。  |  string  | 
|  sourceVpcArn  |  發出請求之 VPC 的 ARN。  |  arn：aws：ec2：*region*：*account*：vpc/*id*  | 
| failureReason | 指出請求失敗的原因。可能值如下： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/vpc-lattice/latest/ug/monitoring-access-logs.html) | string | 

**範例**  
以下為日誌項目的範例。

```
{
    "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>

下表說明資源存取日誌項目的欄位。


| 欄位 | Description | 格式 | 
| --- | --- | --- | 
|  serviceNetworkArn  |  服務網路 ARN。  |  arn：*partition* vpc-lattice：*region*：*account*：servicenetwork/*id*  | 
|  serviceNetworkResourceAssociationId  |  服務網路資源 ID。  |  *snra*-*xxx*  | 
|  vpcEndpointId  |  用來存取資源的端點 ID。  |  string  | 
|  sourceVpcArn  |  來源 VPC ARN 或起始連線的 VPC。  |  string  | 
|  resourceConfigurationArn  |  已存取之資源組態的 ARN。  |  string  | 
|  protocol  |  用來與資源組態通訊的通訊協定。目前僅支援 tcp。  |  string  | 
|  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_tw/vpc-lattice/latest/ug/monitoring-access-logs.html)  | 
|  HTTP 403：禁止  |  已為服務設定身分驗證，但傳入的請求未經過身分驗證或授權。  | 
|  HTTP 404：不存在的服務  |  您嘗試連線到不存在或未註冊至正確服務網路的服務。  | 
|  HTTP 500：內部伺服器錯誤  |  VPC Lattice 發生錯誤，例如無法連線至目標。  | 
|  HTTP 502：無效的閘道  |  VPC Lattice 發生錯誤。  | 

# Amazon VPC Lattice 的 CloudTrail 日誌
<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 Lattice 主控台的呼叫，以及對 VPC Lattice API 操作的程式碼呼叫。您可以使用 CloudTrail 所收集的資訊，判斷對 VPC Lattice 提出的請求、提出請求的 IP 地址、提出請求的時間，以及其他詳細資訊。

每一筆事件或日誌專案都會包含產生請求者的資訊。身分資訊可協助您判斷下列事項：
+ 該請求是使用根使用者還是使用者憑證提出。
+ 請求是否代表 IAM Identity Center 使用者提出。
+ 提出該請求時，是否使用了特定角色或聯合身分使用者的暫時安全憑證。
+ 該請求是否由另一項 AWS 服務服務提出。

當您建立帳戶 AWS 帳戶 時CloudTrail 會在您的 中處於作用中狀態，而且您會自動存取 CloudTrail **事件歷史記錄**。CloudTrail **事件歷史記錄**為 AWS 區域中過去 90 天記錄的管理事件，提供可檢視、可搜尋、可下載且不可變的記錄。如需詳細資訊，請參閱「AWS CloudTrail 使用者指南」**中的[使用 CloudTrail 事件歷史記錄](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。檢視**事件歷史記錄**不會產生 CloudTrail 費用。

如需 AWS 帳戶 過去 90 天內持續記錄的事件，請建立線索或 [CloudTrail Lake](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)。  
您可以透過建立追蹤，免費將持續管理事件的一個複本從 CloudTrail 傳遞至您的 Amazon S3 儲存貯體，但這樣做會產生 Amazon S3 儲存費用。如需 CloudTrail 定價的詳細資訊，請參閱 [AWS CloudTrail 定價](https://aws.amazon.com/cloudtrail/pricing/)。如需 Amazon S3 定價的相關資訊，請參閱 [Amazon S3 定價](https://aws.amazon.com/s3/pricing/)。

**CloudTrail Lake 事件資料存放區**  
*CloudTrail Lake* 讓您能夠對事件執行 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 Lake 事件資料存放區和查詢會產生費用。建立事件資料存放區時，您可以選擇要用於事件資料存放區的[定價選項](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)。

## CloudTrail 中的 VPC Lattice 管理事件
<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 Lattice 控制平面操作記錄為管理事件。如需 VPC Lattice 記錄到 CloudTrail 的 Amazon VPC Lattice 控制平面操作清單，請參閱 [Amazon VPC Lattice API 參考](https://docs.aws.amazon.com/vpc-lattice/latest/APIReference/)。

## VPC Lattice 事件範例
<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 record contents](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-record-contents.html)。