

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

# AWS Transfer Family 伺服器 Amazon CloudWatch 記錄
<a name="structured-logging"></a>

Amazon CloudWatch 是一項強大的監控和可觀測性服務，可讓您全面了解 AWS 資源，包括 AWS Transfer Family。
+ 即時監控：CloudWatch 會即時監控 Transfer Family 資源和應用程式，讓您追蹤和分析其效能。
+ 指標收集：CloudWatch 會為您的資源和應用程式收集和追蹤各種指標，這些是您可以測量和用於分析的變數。
+ CloudWatch 首頁：CloudWatch 首頁會自動顯示 Transfer Family 和您使用之 AWS 其他服務的指標，提供監控資料的集中檢視。
+ 自訂儀表板：您可以在 CloudWatch 中建立自訂儀表板，以顯示自訂應用程式的特定指標，以及您選擇監控的資源。
+ 警示和通知：CloudWatch 可讓您建立警示，以監控指標，並在超過特定閾值時觸發通知或自動化動作。這對於監控 Transfer Family 伺服器中的檔案傳輸活動以及相應地擴展資源非常有用。
+ 成本最佳化：您可以使用 CloudWatch 收集的資料來識別未充分利用的資源，並採取動作，例如停止或刪除執行個體，以最佳化您的成本。

整體而言，CloudWatch 中全面的監控功能使其成為管理和最佳化 Transfer Family 基礎設施及其上執行應用程式的重要工具。

Transfer Family Web 應用程式的 CloudWatch 記錄詳細資訊可在 中找到[Transfer Family Web 應用程式的 CloudTrail 記錄](webapp-cloudtrail.md)。

## Transfer Family 的 CloudWatch 記錄類型
<a name="log-tf-types"></a>

Transfer Family 提供兩種將事件記錄到 CloudWatch 的方式：
+ JSON 結構化日誌記錄
+ 透過記錄角色記錄

對於 Transfer Family 伺服器，您可以選擇您偏好的記錄機制。對於連接器和工作流程，僅支援記錄角色。

**JSON 結構化記錄**

對於記錄伺服器事件，建議使用 JSON 結構化記錄。這可提供更全面的日誌格式，以啟用 CloudWatch 日誌查詢。對於這種類型的記錄，建立伺服器 （或編輯伺服器記錄組態） 之使用者的 IAM 政策必須包含下列許可：
+ `logs:CreateLogDelivery`
+ `logs:DeleteLogDelivery`
+ `logs:DescribeLogGroups`
+ `logs:DescribeResourcePolicies`
+ `logs:GetLogDelivery`
+ `logs:ListLogDeliveries`
+ `logs:PutResourcePolicy`
+ `logs:UpdateLogDelivery`

政策範例如下。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogDelivery",
                "logs:GetLogDelivery",
                "logs:UpdateLogDelivery",
                "logs:DeleteLogDelivery",
                "logs:ListLogDeliveries",
                "logs:PutResourcePolicy",
                "logs:DescribeResourcePolicies",
                "logs:DescribeLogGroups"                
            ],
            "Resource": "*"
        }
    ]
}
```

如需設定 JSON 結構化記錄的詳細資訊，請參閱 [建立、更新和檢視伺服器的記錄](log-server-manage.md)。

**記錄角色**

若要記錄連接到伺服器的受管工作流程以及連接器的事件，您需要指定記錄角色。若要設定存取，您可以建立以資源為基礎的 IAM 政策和提供該存取資訊的 IAM 角色。以下是 AWS 帳戶 可記錄伺服器事件的範例政策。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:DescribeLogStreams",
                "logs:CreateLogGroup",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/transfer/*"
        }
    ]
}
```

如需設定記錄角色以記錄工作流程事件的詳細資訊，請參閱 [管理工作流程的記錄](cloudwatch-workflows.md)。

# 建立、更新和檢視伺服器的記錄
<a name="log-server-manage"></a>

對於所有 AWS Transfer Family 伺服器，我們提供結構化記錄。建議您對所有新的和現有的 Transfer Family 伺服器使用結構化記錄。使用結構化記錄的優勢包括：
+ 以結構化 JSON 格式接收日誌。
+ 使用 Amazon CloudWatch Logs Insights 查詢您的日誌，自動探索 JSON 格式欄位。
+ 跨 AWS Transfer Family 資源共用日誌群組可讓您將多個伺服器的日誌串流合併為單一日誌群組，讓您更輕鬆地管理監控組態和日誌保留設定。
+ 建立可新增至 CloudWatch 儀表板的彙總指標和視覺化。
+ 使用日誌群組來建立合併日誌指標、視覺化效果和儀表板，以追蹤用量和效能資料。

若要啟用連接到伺服器的工作流程記錄，您必須使用記錄角色。

**注意**  
當您新增記錄角色時，記錄群組一律為 `/aws/transfer/your-serverID`，且無法變更。這表示，除非您將結構化伺服器日誌傳送到相同的群組，否則您會記錄到兩個不同的記錄群組。  
如果您知道要將工作流程與伺服器建立關聯，因此需要新增記錄角色，您可以設定結構化記錄來記錄 的預設日誌群組`/aws/transfer/your-serverID`。  
若要修改您的記錄群組，請參閱 *AWS Transfer Family API 參考*中的 [StructuredLogDestinations](https://docs.aws.amazon.com/transfer/latest/APIReference/API_UpdateServer.html#TransferFamily-UpdateServer-request-StructuredLogDestinations)。

如果您使用 Transfer Family 主控台建立新伺服器，預設會啟用記錄。建立伺服器之後，您可以使用 `UpdateServer` API 操作來變更記錄組態。如需詳細資訊，請參閱 [StructuredLogDestinations](https://docs.aws.amazon.com/transfer/latest/APIReference/API_UpdateServer.html#TransferFamily-UpdateServer-request-StructuredLogDestinations)。

目前，對於工作流程，如果您想要啟用記錄功能，您必須指定記錄角色：
+ 如果您使用 `CreateServer`或 `UpdateServer` API 操作將工作流程與伺服器建立關聯，系統不會自動建立記錄角色。如果您想要記錄工作流程事件，您需要明確地將記錄角色連接到伺服器。
+ 如果您使用 Transfer Family 主控台建立伺服器並連接工作流程，日誌會傳送到名稱中包含伺服器 ID 的日誌群組。格式為 `/aws/transfer/server-id`，例如 `/aws/transfer/s-1111aaaa2222bbbb3`。伺服器日誌可以傳送到這個相同的日誌群組或不同的日誌群組。

**在主控台中建立和編輯伺服器的記錄考量事項**
+ 透過主控台建立的新伺服器僅支援結構化 JSON 記錄，除非工作流程連接到伺服器。
+ *對於您在 主控台中建立的新伺服器，沒有記錄*選項。
+ 現有的伺服器可以隨時透過主控台啟用結構化 JSON 記錄。
+ 透過主控台啟用結構化 JSON 記錄會停用現有的記錄方法，以免向客戶重複收費。例外狀況是工作流程已連接至伺服器。
+ 如果您啟用結構化 JSON 記錄，您稍後無法透過主控台將其停用。
+ 如果您啟用結構化 JSON 記錄，您可以隨時透過主控台變更日誌群組目的地。
+ 如果您啟用結構化 JSON 記錄，且已透過 API 啟用這兩種記錄類型，則無法透過主控台編輯記錄角色。例外情況是，如果您的伺服器已連接工作流程。不過，記錄角色會繼續出現在**其他詳細資訊**中。

**使用 API 或 SDK 建立和編輯伺服器的記錄考量**
+ 如果您透過 API 建立新伺服器，您可以設定記錄的其中一種或兩種類型，或選擇不記錄。
+ 對於現有的伺服器，可隨時啟用和停用結構化 JSON 記錄。
+ 您可以隨時透過 API 變更日誌群組。
+ 您可以隨時透過 API 變更記錄角色。

**若要啟用結構化記錄，您必須使用下列許可登入 帳戶**
+ `logs:CreateLogDelivery`
+ `logs:DeleteLogDelivery`
+ `logs:DescribeLogGroups`
+ `logs:DescribeResourcePolicies`
+ `logs:GetLogDelivery`
+ `logs:ListLogDeliveries`
+ `logs:PutResourcePolicy`
+ `logs:UpdateLogDelivery`

範例政策可在 區段中取得[設定 CloudWatch 記錄角色](configure-cw-logging-role.md)。

**Topics**
+ [建立伺服器的記錄](#log-server-create)
+ [更新伺服器的記錄](#log-server-update)
+ [檢視伺服器組態](#log-server-config)

## 建立伺服器的記錄
<a name="log-server-create"></a>

當您建立新的伺服器時，您可以在**設定其他詳細資訊**頁面上指定現有的日誌群組，或建立新的日誌群組。

![\[在建立伺服器精靈中設定其他詳細資訊的記錄窗格。選擇已選取的現有日誌群組。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-choose-existing-group.png)


如果您選擇**建立日誌群組**，CloudWatch 主控台 ([https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/)：//) 會開啟**建立日誌群組**頁面。如需詳細資訊，請參閱在 [ CloudWatch Logs 中建立日誌群組](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#Create-Log-Group)。

## 更新伺服器的記錄
<a name="log-server-update"></a>

記錄的詳細資訊取決於您更新的案例。

**注意**  
當您選擇使用結構化 JSON 記錄時，可能會發生延遲，在極少數情況下，Transfer Family 會停止以舊格式記錄，但需要一些時間才能開始以新的 JSON 格式記錄。這可能會導致未記錄的事件。不會有任何服務中斷，但您應該在變更記錄方法後的第一個小時內謹慎傳輸檔案，因為日誌可能會遭到捨棄。

如果您要編輯現有的伺服器，您的選項取決於伺服器的狀態。
+ 伺服器已啟用記錄角色，但尚未啟用結構化 JSON 記錄。  
![\[記錄窗格，顯示現有的記錄角色。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-choose-role.png)
+ 伺服器未啟用任何記錄。  
![\[如果伺服器未啟用任何記錄，則記錄窗格。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-edit-none.png)
+ 伺服器已啟用結構化 JSON 記錄，但尚未指定記錄角色。  
![\[如果伺服器尚未啟用記錄，則記錄窗格。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-edit-add-json-02.png)
+ 伺服器已啟用結構化 JSON 記錄，也已指定記錄角色。  
![\[如果伺服器已啟用結構化記錄，且還指定了記錄角色，則記錄窗格。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-edit-both.png)

## 檢視伺服器組態
<a name="log-server-config"></a>

伺服器組態頁面的詳細資訊取決於您的案例：

根據您的案例，伺服器組態頁面可能看起來像下列其中一個範例：
+ 未啟用記錄。  
![\[未設定記錄的記錄組態。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-config-none.png)
+ 已啟用結構化 JSON 記錄。  
![\[已設定結構化記錄的日誌記錄組態。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-config-structured.png)
+ 已啟用記錄角色，但未啟用結構化 JSON 記錄。  
![\[已設定記錄角色的記錄組態。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-config-legacy.png)
+ 這兩種記錄類型 （記錄角色和結構化 JSON 記錄） 都已啟用。  
![\[同時設定記錄類型的記錄組態 （記錄角色和結構化 JSON 記錄）。\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/logging-server-config-both.png)

# 管理工作流程的記錄
<a name="cloudwatch-workflows"></a>

CloudWatch 提供工作流程進度和結果的合併稽核和記錄。此外， 為工作流程 AWS Transfer Family 提供數個指標。您可以檢視前一分鐘有多少工作流程執行開始、成功完成和失敗的指標。Transfer Family 的所有 CloudWatch 指標如 中所述[使用 Transfer Family 伺服器的 CloudWatch 指標](metrics.md)。

**檢視工作流程的 Amazon CloudWatch logs**

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

1. 在左側導覽窗格中，選擇**日誌**，然後選擇**日誌群組**。

1. 在**日誌群組**頁面上的導覽列上，為您的 AWS Transfer Family 伺服器選擇正確的區域。

1. 選擇對應至您伺服器的日誌群組。

   例如，如果您的伺服器 ID 為 `s-1234567890abcdef0`，您的日誌群組為 `/aws/transfer/s-1234567890abcdef0`。

1. 在伺服器的日誌群組詳細資訊頁面上，會顯示最新的日誌串流。您要探索的使用者有兩個日誌串流：
   + 每個 Secure Shell (SSH) 檔案傳輸通訊協定 (SFTP) 工作階段各一個。
   + 一個 用於為您的伺服器執行的工作流程。工作流程的日誌串流格式為 `username.workflowID.uniqueStreamSuffix`。

   例如，如果您的使用者是 `mary-major`，您有下列日誌串流：

   ```
   mary-major-east.1234567890abcdef0
   mary.w-abcdef01234567890.021345abcdef6789
   ```
**注意**  
 此範例中列出的 16 位數英數識別符是虛構的。您在 Amazon CloudWatch 中看到的值不同。

的**日誌事件**頁面`mary-major-usa-east.1234567890abcdef0`會顯示每個使用者工作階段的詳細資訊，而`mary.w-abcdef01234567890.021345abcdef6789`日誌串流包含工作流程的詳細資訊。

 以下是 的範例日誌串流`mary.w-abcdef01234567890.021345abcdef6789`，以包含複製步驟的工作流程 (`w-abcdef01234567890`) 為基礎。

```
{
    "type": "ExecutionStarted",
    "details": {
        "input": {
            "initialFileLocation": {
                "bucket": "amzn-s3-demo-bucket",
                "key": "mary/workflowSteps2.json",
                "versionId": "version-id",
                "etag": "etag-id"
            }
        }
    },
    "workflowId":"w-abcdef01234567890",
    "executionId":"execution-id",
    "transferDetails": {
        "serverId":"s-server-id",
        "username":"mary",
        "sessionId":"session-id"
    }
},
{
    "type":"StepStarted",
    "details": {
        "input": {
            "fileLocation": {
                "backingStore":"S3",
                "bucket":"amzn-s3-demo-bucket",
                "key":"mary/workflowSteps2.json",
                "versionId":"version-id",
                "etag":"etag-id"
            }
        },
        "stepType":"COPY",
        "stepName":"copyToShared"
    },
    "workflowId":"w-abcdef01234567890",
    "executionId":"execution-id",
    "transferDetails": {
        "serverId":"s-server-id",
        "username":"mary",
        "sessionId":"session-id"
    }
},
{
    "type":"StepCompleted",
    "details":{
        "output":{},
        "stepType":"COPY",
        "stepName":"copyToShared"
    },
    "workflowId":"w-abcdef01234567890",
    "executionId":"execution-id",
    "transferDetails":{
        "serverId":"server-id",
        "username":"mary",
        "sessionId":"session-id"
    }
},
{
    "type":"ExecutionCompleted",
    "details": {},
    "workflowId":"w-abcdef01234567890",
    "executionId":"execution-id",
    "transferDetails":{
        "serverId":"s-server-id",
        "username":"mary",
        "sessionId":"session-id"
    }
}
```

# 設定 CloudWatch 記錄角色
<a name="configure-cw-logging-role"></a>

若要設定存取，您可以建立以資源為基礎的 IAM 政策和提供該存取資訊的 IAM 角色。

若要啟用 Amazon CloudWatch 記錄，請先建立啟用 CloudWatch 記錄的 IAM 政策。然後，您可以建立 IAM 角色，並將政策連接到該角色。您可以在[建立伺服器](getting-started.md#getting-started-server)或[編輯現有伺服器](edit-server-config.md)時執行此操作。如需 CloudWatch 的詳細資訊，請參閱《[Amazon CloudWatch 使用者指南》中的什麼是 Amazon CloudWatch？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)*和 Amazon CloudWatch*[什麼是 Amazon CloudWatch Amazon CloudWatch logs？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)。

使用下列範例 IAM 政策來允許 CloudWatch 記錄。

------
#### [ Use a logging role ]

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:DescribeLogStreams",
                "logs:CreateLogGroup",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/transfer/*"
        }
    ]
}
```

------
#### [ Use structured logging ]

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogDelivery",
                "logs:GetLogDelivery",
                "logs:UpdateLogDelivery",
                "logs:DeleteLogDelivery",
                "logs:ListLogDeliveries",
                "logs:PutResourcePolicy",
                "logs:DescribeResourcePolicies",
                "logs:DescribeLogGroups"                
            ],
            "Resource": "*"
        }
    ]
}
```

在上述範例政策中，對於 **Resource**，將 *region-id* 和 取代*AWS 帳戶*為您的值。例如 **"Resource": "arn:aws::logs:us-east-1:111122223333:log-group:/aws/transfer/\$1"**

------

然後，您可以建立角色並連接您建立的 CloudWatch Logs 政策。

**建立 IAM 角色並連接政策**

1. 在導覽窗格中，選擇**角色**，然後選擇**建立角色**。

   在**建立角色**頁面上，確定已選擇 **AWS 服務**。

1. 從服務清單選擇 **Transfer (傳輸)**，然後選擇 **Next: Permissions (下一步：許可)**。這會在 AWS Transfer Family 和 IAM 角色之間建立信任關係。此外，新增 `aws:SourceAccount` 和 `aws:SourceArn`條件金鑰，以保護自己免於*混淆代理人*問題。如需詳細資訊，請參閱下列文件：
   + 與下列項目建立信任關係的程序 AWS Transfer Family： [建立信任關係](requirements-roles.md#establish-trust-transfer)
   + 混淆代理人問題的描述：[混淆代理人問題](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html)

1. 在**連接許可政策**區段中，尋找並選擇您剛建立的 CloudWatch Logs 政策，然後選擇**下一步：標籤**。

1. (選用) 輸入標籤的金鑰和值，然後選擇 **Next: Review (下一步：檢閱)**。

1. 在 **Review (檢閱)** 頁面上，輸入您新角色的名稱和描述，然後選擇 **Create role (建立角色)**。

1. 若要檢視日誌，請選擇**伺服器 ID** 以開啟伺服器組態頁面，然後選擇**檢視日誌**。系統會將您重新導向至 CloudWatch 主控台，您可以在其中查看日誌串流。

在伺服器的 CloudWatch 頁面上，您可以查看使用者身分驗證 （成功和失敗）、資料上傳 (`PUT` 操作） 和資料下載 (`GET` 操作） 的記錄。

# 檢視 Transfer Family 日誌串流
<a name="view-log-entries"></a>

**檢視 Transfer Family 伺服器日誌**

1. 導覽至伺服器的詳細資訊頁面。

1. 選擇**檢視日誌**。這會開啟 Amazon CloudWatch。

1. 隨即顯示所選伺服器的日誌群組。  
![\[\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/log-example-01.png)

1. 您可以選取日誌串流，以顯示串流的詳細資訊和個別項目。
   + 如果有 **ERRORS** 的清單，您可以選擇它來檢視伺服器最新錯誤的詳細資訊。  
![\[\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/log-example-errors.png)
   + 選擇任何其他項目以查看範例日誌串流。  
![\[\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/log-example-02.png)
   + 如果您的伺服器具有與其相關聯的受管工作流程，您可以檢視工作流程執行的日誌。
**注意**  
工作流程的日誌串流格式為 `username.workflowId.uniqueStreamSuffix`。例如，**decrypt-user.w-a1111222233334444.aaaa1111bbbb2222** 可以是使用者**decrypt-user**和工作流程 的日誌串流名稱**w-a1111222233334444**。  
![\[\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/images/log-example-workflow.png)

**注意**  
對於任何展開的日誌項目，您可以選擇複製，將項目複製到剪貼簿****。如需 CloudWatch 日誌的詳細資訊，請參閱[檢視日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#ViewingLogData)。

## 建立 Amazon CloudWatch 警示
<a name="monitoring-cloudwatch-examples"></a>

下列範例示範如何使用 AWS Transfer Family 指標 建立 Amazon CloudWatch 警示`FilesIn`。

------
#### [ CDK ]

```
new cloudwatch.Metric({
  namespace: "AWS/Transfer",
  metricName: "FilesIn",
  dimensionsMap: { ServerId: "s-00000000000000000" },
  statistic: "Average",
  period: cdk.Duration.minutes(1),
}).createAlarm(this, "AWS/Transfer FilesIn", {
  threshold: 1000,
  evaluationPeriods: 10,
  datapointsToAlarm: 5,
  comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
});
```

------
#### [ CloudFormation ]

```
Type: AWS::CloudWatch::Alarm
Properties:
  Namespace: AWS/Transfer
  MetricName: FilesIn
  Dimensions:
    - Name: ServerId
      Value: s-00000000000000000
  Statistic: Average
  Period: 60
  Threshold: 1000
  EvaluationPeriods: 10
  DatapointsToAlarm: 5
  ComparisonOperator: GreaterThanOrEqualToThreshold
```

------

## 將 Amazon S3 API 操作記錄到 S3 存取日誌
<a name="monitoring-s3-access-logs"></a>

**注意**  
本節不適用於 Transfer Family Web 應用程式。

如果您[使用 Amazon S3 存取日誌來識別代表您的檔案傳輸使用者提出的 S3 請求](https://docs.aws.amazon.com/AmazonS3/latest/dev/using-s3-access-logs-to-identify-requests.html)，`RoleSessionName`則 會用來顯示擔任哪個 IAM 角色來服務檔案傳輸。它也會顯示其他資訊，例如用於傳輸的使用者名稱、工作階段 ID 和伺服器 ID。格式為 `[AWS:Role Unique Identifier]/username.sessionid@server-id`，且包含在申請者欄位中。例如，以下是已複製到 S3 儲存貯體之檔案的 S3 存取日誌中請求者範例欄位的內容。 S3 

`arn:aws:sts::AWS-Account-ID:assumed-role/IamRoleName/username.sessionid@server-id`

在上方的申請者欄位中，會顯示名為 的 IAM 角色`IamRoleName`。如需 IAM 角色唯一識別符的詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[唯一識別符](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids)。

# 限制混淆代理人問題的範例
<a name="cloudwatch-confused-deputy"></a>

混淆代理人問題屬於安全性議題，其中沒有執行動作許可的實體可以強制具有更多許可的實體執行該動作。在 中 AWS，跨服務模擬可能會導致混淆代理人問題。如需詳細資訊，請參閱[預防跨服務混淆代理人](confused-deputy.md)。

**注意**  
在下列範例中，將每個*使用者輸入預留位置*取代為您自己的資訊。  
在這些範例中，如果您的伺服器沒有連接任何工作流程，您可以移除工作流程的 ARN 詳細資訊。

下列範例記錄/呼叫政策允許帳戶中的任何伺服器 （和工作流程） 擔任該角色。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowAllServersWithWorkflowAttached",
            "Effect": "Allow",
            "Principal": {
                "Service": "transfer.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "aws:SourceAccount": "111122223333"
                },
                "ArnLike": {
                   "aws:SourceArn": [
                     "arn:aws:transfer:us-west-2:111122223333:server/*",
                     "arn:aws:transfer:us-west-2:111122223333:workflow/*"
                   ]
                }
            }
        }
    ]
}
```

下列範例記錄/叫用政策允許特定伺服器 （和工作流程） 擔任該角色。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowSpecificServerWithWorkflowAttached",
            "Effect": "Allow",
            "Principal": {
                "Service": "transfer.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "aws:SourceAccount": "111122223333"
                },
                "ArnEquals": {
                   "aws:SourceArn": [
                       "arn:aws:transfer:us-west-2:111122223333:server/server-id",
                       "arn:aws:transfer:us-west-2:111122223333:workflow/workflow-id"
                   ]
                }
            }
        }
    ]
}
```

# Transfer Family 的 CloudWatch 日誌結構
<a name="cw-structure-logs"></a>

本主題說明 Transfer Family 日誌中填入的欄位：適用於 JSON 結構化日誌項目和舊版日誌項目。

**Topics**
+ [Transfer Family 的 JSON 結構化日誌](#json-log-entries)
+ [Transfer Family 的舊版日誌](#legacy-log-entries)

## Transfer Family 的 JSON 結構化日誌
<a name="json-log-entries"></a>

下表包含 Transfer Family SFTP/FTP/FTPS 動作的日誌項目欄位詳細資訊，採用新的 JSON 結構化日誌格式。


| 欄位 | 描述 | 項目範例 | 
| --- |--- |--- |
| activity-type | The action by the user | 可用的活動類型如下：`AUTH_FAILURE`、`CONNECTED`、`DISCONNECTED`、`ERROR``EXIT_REASON`、`CLOSE`、`CREATE_SYMLINK`、`DELETE`、`MKDIR`、`OPEN`、`PARTIAL_CLOSE`、`RENAME`、、`RMDIR`、、`SETSTAT`、、、、、、、、`TLS_RESUME_FAILURE`、。 | 
| bytes-in | Number of bytes uploaded by the user | 29238420042 | 
| bytes-out | Number of bytes downloaded by the user | 23094032490328 | 
| ciphers | Specifies the SSH cipher negotiated for the connection (available ciphers are listed in [密碼編譯演算法](security-policies.md#cryptographic-algorithms)) | aes256-gcm@openssh.com | 
| client | The user's client software | SSH-2.0-OpenSSH\$17.4 | 
| home-dir | The directory that the end user lands on when they connect to the endpoint if their home directory type is PATH: if they have a logical home directory, this value is always / | /user-home-bucket/test | 
| kex | Specifies the negotiated SSH key exchange (KEX) for the connection (available KEX are listed in [密碼編譯演算法](security-policies.md#cryptographic-algorithms)) | diffie-hellman-group14-sha256 | 
| message | Provides more information related to the error | ＜字串＞ | 
| method | The authentication method | publickey | 
| mode | Specifies how a client opens a file | CREATE \$1 TRUNCATE \$1 WRITE | 
| operation | The client operation on a file | OPEN \$1 CLOSE | 
| path | Actual file path affected | /amzn-s3-demo-bucket/test-file-1.pdf  | 
| ssh-public-key | The public key body for the user that is connecting | AAAAC3NzaC1lZDI1NTE5AAAAIA9OY0qV6XYVHaaOiWAcj2spDJVbgjrqDPY4pxd6GnHl | 
| ssh-public-key-fingerprint | 列出使用者金鑰時，服務受管使用者在主控台中顯示的公有金鑰指紋。  在 主控台中，指紋會以填充字元 （如果有的話） 顯示：從 0 到 3 等號 (=) 結尾。在日誌項目中，此填充會從輸出分割。  | SHA256:BY3gNMHwTfjd4n2VuT4pTyLOk82zWZj4KEYEu7y4r/0 | 
| ssh-public-key-type | Type of public key: Transfer Family supports RSA-, ECDSA-, and ED25519-formatted keys | ssh-ed25519 | 
| resource-arn | A system-assigned, unique identifier for a specific resource (for example, a server) |  arn：aws：transfer：ap-northeast-1：12346789012：server/s-1234567890akeu2js2  | 
| role | The IAM role of the user |  arn：aws：iam：：0293883675：role/testuser-role  | 
| session-id | A system-assigned, unique identifier for a single session |  9ca9a0e1cec6ad9d  | 
| source-ip | Client IP address | 18.323.0.129 | 
| user | The end user's username | myname192 | 
| user-policy | The permissions specified for the end user: this field is populated if the user's policy is a session policy. | The JSON code for the session policy that is being used | 

## Transfer Family 的舊版日誌
<a name="legacy-log-entries"></a>

下表包含各種 Transfer Family 動作的日誌項目詳細資訊。

**注意**  
 這些項目不是新的 JSON 結構化日誌格式。

下表包含各種 Transfer Family 動作的日誌項目詳細資訊，採用新的 JSON 結構化日誌格式。




| 動作 | Amazon CloudWatch Logs 中的對應日誌 | 
| --- | --- | 
| 身分驗證失敗 |  ERRORS AUTH\$1FAILURE Method=publickey User=lhr Message="RSA SHA256：Lfz3R2nmLY4raK\$1b7Rb1rSvUIbAE\$1a\$1Hxg0c7l1JIZ0" SourceIP=3.8.172.211   | 
| COPY/TAG/DELETE/DECRYPT 工作流程 |  \$1"type"："StepStarted"，"details"：\$1"input"：\$1"fileLocation"：\$1"backingStore"："EFS"，"filesystemId"："fs-12345678"，"path"："/lhr/regex.py"\$1\$1，"stepType"："TAG"，"stepName"："successful\$1tag\$1step"\$1，"workflowId"："w-1111aaaa222bb3"，"executionId"："81234abcd-1234-efgh-5678-ijklmnopqr90"，"transferDetails"：\$1serverId"："s-124abcd55"user."sessionId1234567890  | 
| 自訂步驟工作流程 |  \$1"type"："CustomStepInvoked"，"details"：\$1"output"：\$1"token"："MzM4Mjg5YWUtYTEzMy00YjIzLWI3OGMtYzU4OGI2ZjQyMzE5"\$1，"stepType"："CUSTOM"，"stepName"："efs-s3\$1copy\$12"\$1，"workflowId"："w-9283e49d3297c3f7"，"executionId"："1234abcd-1234-efgh-5678-ijklmnopr90"，"transferDetails：\$11"serverId"1."sessionId1234567890  | 
| 刪除 |  lhr.33a8fb495ffb383b DELETE Path=/bucket/user/123.jpg  | 
| 下載 |  lhr.33a8fb495ffb383b OPEN Path=/bucket/user/123.jpg Mode=READ llhr.33a8fb495ffb383b CLOSE Path=/bucket/user/123.jpg BytesOut=3618546  | 
| 登入/登出 |  user.914984e553bcddb6 CONNECTED SourceIP=1.22.111.222 User=lhr HomeDir=LOGICAL Client=SSH-2.0-OpenSSH\$17.4 Role=arn：aws：：iam：：123456789012：role/sftp-s3-access user.914984e553bcddb6 DISCONNECTED  | 
| 重新命名 |  lhr.33a8fb495ffb383b RENAME Path=/bucket/user/lambo.png NewPath=/bucket/user/ferrari.png   | 
| 工作流程錯誤日誌範例 |  \$1"type"："StepErrored"，"details"：\$1"errorType"："BAD\$1REQUEST"，"errorMessage"："Cannot tag Efs file"，"stepType"："TAG"，"stepName"："successful\$1tag\$1step"\$1，"workflowId"："w-1234abcd5678efghi"，"executionId"："81234abcd-1234-efgh-5678-ijklmnopqr90"，"transferDetails"：\$1"serverId"："s-1234abcd5678efghi"，"username"："ldefchr""："1234567890sessionId："  | 
| Symlinks |  lhr.eb49cf7b8651e6d5 CREATE\$1SYMLINK LinkPath=/fs-12345678/lhr/pqr.jpg TargetPath=abc.jpg   | 
| 上傳 |  lhr.33a8fb495ffb383b OPEN Path=/bucket/user/123.jpg Mode=CREATE\$1TRUNCATE\$1WRITE lhr.33a8fb495ffb383b CLOSE Path=/bucket/user/123.jpg BytesIn=3618546  | 
| 工作流程 |  \$1"type"："ExecutionStarted"，"details"：\$1"input"：\$1"initialFileLocation"：\$1"backingStore"："EFS"，"filesystemId"："fs-12345678"，"path"："/lhr/regex.py"\$1\$1\$1，"workflowId"："w-1111aaa222bb3"，"executionId"："1234abcd-1234-efgh-5678-ijklmnopqr90"，"transferDetails"：\$1"serverId"："szz-zz111aaa2223"，"username"lhr"："sessionId"：1234567890 \$1"type"："StepStarted"，"details"：\$1"input"：\$1"fileLocation"：\$1"backingStore"："EFS"，"filesystemId"："fs-12345678"，"path"："/lhr/regex.py"\$1\$1，"stepType"："CUSTOM"，"stepName"："efs-s3\$1copy\$12"\$1，"workflowId"："w-9283e49d3297c3f7"，"executionId"："1234abcd-1234-efgh-5678-ijklmnopr90"，"transferDetails"：\$1"serverId"s-189db49d2"sessionId1234567890  | 

# CloudWatch 日誌項目範例
<a name="cw-example-logs"></a>

本主題提供範例日誌項目。

**Topics**
+ [轉移工作階段日誌項目範例](#session-log-examples)
+ [SFTP 連接器的範例日誌項目](#example-sftp-connector-logs)
+ [VPC Lattice 連接器的範例日誌項目](#example-vpc-lattice-connector-logs)
+ [金鑰交換演算法失敗的範例日誌項目](#example-kex-logs)

## 轉移工作階段日誌項目範例
<a name="session-log-examples"></a>

在此範例中，SFTP 使用者連線至 Transfer Family 伺服器、上傳檔案，然後中斷與工作階段的連線。

下列日誌項目反映連線至 Transfer Family 伺服器的 SFTP 使用者。

```
{
   "role": "arn:aws:iam::500655546075:role/transfer-s3",
   "activity-type": "CONNECTED",
   "ciphers": "chacha20-poly1305@openssh.com,chacha20-poly1305@openssh.com",
   "client": "SSH-2.0-OpenSSH_7.4",
   "source-ip": "52.94.133.133",
   "resource-arn": "arn:aws:transfer:us-east-1:500655546075:server/s-3fe215d89f074ed2a",
   "home-dir": "/test/log-me",
   "ssh-public-key": "AAAAC3NzaC1lZDI1NTE5AAAAIA9OY0qV6XYVHaaOiWAcj2spDJVbgjrqDPY4pxd6GnHl",
   "ssh-public-key-fingerprint": "SHA256:BY3gNMHwTfjd4n2VuT4pTyLOk82zWZj4KEYEu7y4r/0",
   "ssh-public-key-type": "ssh-ed25519",
   "user": "log-me",
   "kex": "ecdh-sha2-nistp256",
   "session-id": "9ca9a0e1cec6ad9d"
}
```

下列日誌項目反映 SFTP 使用者將檔案上傳至其 Amazon S3 儲存貯體。

```
{
   "mode": "CREATE|TRUNCATE|WRITE",
   "path": "/test/log-me/config-file",
   "activity-type": "OPEN",
   "resource-arn": "arn:aws:transfer:us-east-1:500655546075:server/s-3fe215d89f074ed2a",
   "session-id": "9ca9a0e1cec6ad9d"
}
```

下列日誌項目反映 SFTP 使用者中斷與其 SFTP 工作階段的連線。首先，用戶端會關閉與儲存貯體的連線，然後用戶端會中斷 SFTP 工作階段的連線。

```
{
   "path": "/test/log-me/config-file",
   "activity-type": "CLOSE",
   "resource-arn": "arn:aws:transfer:us-east-1:500655546075:server/s-3fe215d89f074ed2a",
   "bytes-in": "121",
   "session-id": "9ca9a0e1cec6ad9d"
}

{
   "activity-type": "DISCONNECTED",
   "resource-arn": "arn:aws:transfer:us-east-1:500655546075:server/s-3fe215d89f074ed2a",
   "session-id": "9ca9a0e1cec6ad9d"
}
```

**注意**  
可用的活動類型如下：`AUTH_FAILURE`、`CONNECTED`、`DISCONNECTED`、`ERROR``EXIT_REASON`、`CLOSE`、`CREATE_SYMLINK`、`DELETE`、`MKDIR`、、`OPEN``PARTIAL_CLOSE`、`RENAME`、`RMDIR`、、、`SETSTAT`、、`TLS_RESUME_FAILURE`、。

## SFTP 連接器的範例日誌項目
<a name="example-sftp-connector-logs"></a>

本節包含成功和失敗傳輸的範例日誌。日誌會產生到名為 的日誌群組`/aws/transfer/connector-id`，其中 *connector-id* 是 SFTP 連接器的識別符。當您執行 `StartFileTransfer`或 `StartDirectoryListing`命令時，會產生 SFTP 連接器的日誌項目。

此日誌項目適用於成功完成的傳輸。

```
{
    "operation": "RETRIEVE",
    "timestamp": "2023-10-25T16:33:27.373720Z",
    "connector-id": "connector-id",
    "transfer-id": "transfer-id",
    "file-transfer-id": "transfer-id/file-transfer-id",
    "url": "sftp://192.0.2.0",
    "file-path": "/remotebucket/remotefilepath",
    "status-code": "COMPLETED",
    "start-time": "2023-10-25T16:33:26.945481Z",
    "end-time": "2023-10-25T16:33:27.159823Z",
    "account-id": "480351544584",
    "connector-arn": "arn:aws:transfer:us-east-1:account-id:connector/connector-id",
    "local-directory-path": "/connectors-localbucket",
    "bytes": 514,
    "egress-type": "SERVICE_MANAGED"
}
```

此日誌項目適用於逾時的傳輸，因此無法成功完成。

```
{
    "operation": "RETRIEVE",
    "timestamp": "2023-10-25T22:33:47.625703Z",
    "connector-id": "connector-id",
    "transfer-id": "transfer-id",
    "file-transfer-id": "transfer-id/file-transfer-id",
    "url": "sftp://192.0.2.0",
    "file-path": "/remotebucket/remotefilepath",
    "status-code": "FAILED",
    "failure-code": "TIMEOUT_ERROR",
    "failure-message": "Transfer request timeout.",
    "account-id": "480351544584",
    "connector-arn": "arn:aws:transfer:us-east-1:account-id:connector/connector-id",
    "local-directory-path": "/connectors-localbucket",
    "egress-type": "SERVICE_MANAGED"
}
```

此日誌項目適用於成功的 SEND 操作。

```
{
    "operation": "SEND",
    "timestamp": "2024-04-24T18:16:12.513207284Z",
    "connector-id": "connector-id",
    "transfer-id": "transfer-id",
    "file-transfer-id": "transfer-id/file-transfer-id",
    "url": "sftp://server-id.server.transfer.us-east-1.amazonaws.com",
    "file-path": "/amzn-s3-demo-bucket/my-test-folder/connector-metrics-us-east-1-2024-01-02.csv",
    "status-code": "COMPLETED",
    "start-time": "2024-04-24T18:16:12.295235884Z",
    "end-time": "2024-04-24T18:16:12.461840732Z",
    "account-id": "255443218509",
    "connector-arn": "arn:aws:transfer:us-east-1:account-id:connector/connector-id",
    "bytes": 275,
    "egress-type": "SERVICE_MANAGED"
}
```

先前日誌範例中某些索引鍵欄位的描述。
+ `timestamp` 代表日誌新增至 CloudWatch 的時間。 `start-time`和 `end-time`對應至連接器實際啟動和完成傳輸的時間。
+ `transfer-id` 是為每個`start-file-transfer`請求指派的唯一識別符。如果使用者在單一 `start-file-transfer` API 操作中傳遞多個檔案路徑，則所有檔案都會共用相同的 `transfer-id`。
+ `file-transfer-id` 是為每個傳輸的檔案產生的唯一值。請注意， 的初始部分`file-transfer-id`與 相同`transfer-id`。

## VPC Lattice 連接器的範例日誌項目
<a name="example-vpc-lattice-connector-logs"></a>

本節包含 VPC Lattice 連接器的範例日誌。對於 VPC Lattice 連接器，日誌包含提供連接器組態和網路設定相關資訊的其他欄位。

此日誌項目適用於成功完成的 VPC Lattice 連接器 SEND 操作。

```
{
  "operation": "SEND",
  "timestamp": "2025-09-05T14:20:19.577192454Z",
  "connector-id": "connector-id",
  "transfer-id": "transfer-id",
  "file-transfer-id": "transfer-id/file-transfer-id",
  "file-path": ""/amzn-s3-demo-bucket/my-test-folder/connector-vpc-lattice-us-east-1-2025-03-22.csv"",
  "status-code": "COMPLETED",
  "start-time": "2025-09-05T14:20:19.434072509Z",
  "end-time": "2025-09-05T14:20:19.481453346Z",
  "account-id": "account-id",
  "connector-arn": "arn:aws:transfer:us-east-1:account-id:connector/connector-id",
  "remote-directory-path": "/test-bucket/test-folder/",
  "bytes": 262,
  "egress-type": "VPC_LATTICE",
  "vpc-lattice-resource-configuration-arn": "arn:aws:vpc-lattice:us-east-1:account-id:resourceconfiguration/resource-configuration-arn-id,
  "vpc-lattice-port-number": 22
}
```

VPC Lattice 連接器日誌包含下列其他欄位：
+ `egress-type` - 連接器的輸出組態類型
+ `vpc-lattice-resource-configuration-arn` - 定義目標 SFTP 伺服器位置的 VPC Lattice 資源組態 ARN
+ `vpc-lattice-port-number` - 透過 VPC Lattice 連線至 SFTP 伺服器的連接埠號碼

## 金鑰交換演算法失敗的範例日誌項目
<a name="example-kex-logs"></a>

本節包含金鑰交換演算法 (KEX) 失敗的範例日誌。這些是結構化日誌之 **ERRORS** 日誌串流中的範例。

此日誌項目是發生主機金鑰類型錯誤的範例。

```
{
    "activity-type": "KEX_FAILURE",
    "source-ip": "999.999.999.999",
    "resource-arn": "arn:aws:transfer:us-east-1:999999999999:server/s-999999999999999999",
    "message": "no matching host key type found",
    "kex": "ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-rsa,ssh-dss"
}
```

此日誌項目是 KEX 不相符的範例。

```
{
    "activity-type": "KEX_FAILURE",
    "source-ip": "999.999.999.999",
    "resource-arn": "arn:aws:transfer:us-east-1:999999999999:server/s-999999999999999999",
    "message": "no matching key exchange method found",
    "kex": "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group14-sha256"
}
```

# 使用 Transfer Family 伺服器的 CloudWatch 指標
<a name="metrics"></a>

**注意**  
 您也可以從 Transfer Family 主控台本身取得 Transfer Family 的指標。如需詳細資訊，請參閱[在 主控台中監控用量](monitor-usage-transfer-console.md) 

您可以使用 CloudWatch 指標取得伺服器的相關資訊。*指標*代表發佈至 CloudWatch 的一組按時間排序的資料點。使用指標時，您必須指定 Transfer Family 命名空間、指標名稱和[維度](#cw-dimensions)。如需指標的詳細資訊，請參閱《*Amazon CloudWatch 使用者指南*》中的[指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Metric)。

 下表說明 Transfer Family 的 CloudWatch 指標。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/transfer/latest/userguide/metrics.html)

## Transfer 系列維度
<a name="cw-dimensions"></a>

*維度*是一組名稱值對，是指標身分的一部分。如需維度的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的[維度](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Dimension)。

下表說明 Transfer Family 的 CloudWatch 維度。


| 維度 | Description | 
| --- | --- | 
| `ServerId` | 伺服器的唯一 ID。 | 
| `ConnectorId` | 連接器的唯一 ID。用於 AS2、用於 `OutboundMessage`和 `OutboundFailedMessage` | 

## AWS 使用者通知 搭配 使用 AWS Transfer Family
<a name="using-user-notifications"></a>

若要收到 AWS Transfer Family 事件的通知，您可以使用 [AWS 使用者通知](https://docs.aws.amazon.com/notifications/latest/userguide/what-is.html) 來設定各種交付管道。當事件符合您指定的規則時，您會收到通知。

您可以透過多個管道接收事件通知，包括電子郵件、[聊天應用程式中的 Amazon Q Developer](https://docs.aws.amazon.com/chatbot/latest/adminguide/what-is.html) 聊天通知或 [AWS Console Mobile Application](https://docs.aws.amazon.com/consolemobileapp/latest/userguide/what-is-consolemobileapp.html) 推送通知。您也可以在[主控台通知中心](https://console.aws.amazon.com/notifications/)查看通知。 使用者通知 支援彙總，可減少您在特定事件期間收到的通知數量。

如需詳細資訊，請參閱*AWS 使用者通知 《 使用者指南*》中的[使用 AWS Transfer Family 受管工作流程部落格文章自訂檔案交付通知](https://aws.amazon.com/blogs/storage/customize-file-delivery-notifications-using-aws-transfer-family-managed-workflows/)，以及[什麼是 AWS 使用者通知？](https://docs.aws.amazon.com/notifications/latest/userguide/what-is.html)。

# 使用查詢篩選日誌項目
<a name="cw-queries"></a>

您可以使用 CloudWatch 查詢來篩選和識別 Transfer Family 的日誌項目。本節包含一些範例。

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 您可以建立查詢或規則。
   + 若要建立 **Logs Insights** 查詢，請從左側導覽面板中選擇 **Logs Insights**，然後輸入查詢的詳細資訊。
   + 若要建立 **Contributor Insights** 規則，請從左側導覽面板中選擇 Insights > Contributor Insights，然後輸入規則的詳細資訊。

1. 執行您建立的查詢或規則。

**檢視最佳身分驗證失敗參與者**

在您的結構化日誌中，身分驗證失敗日誌項目看起來類似以下內容：

```
{
  "method":"password",
  "activity-type":"AUTH_FAILURE",
  "source-ip":"999.999.999.999",
  "resource-arn":"arn:aws:transfer:us-east-1:999999999999:server/s-0123456789abcdef",
  "message":"Invalid user name or password",
  "user":"exampleUser"
}
```

執行下列查詢，以檢視身分驗證失敗的主要參與者。

```
filter @logStream = 'ERRORS'
| filter `activity-type` = 'AUTH_FAILURE'
| stats count() as AuthFailures by user, method
| sort by AuthFailures desc
| limit 10
```

您可以建立 **CloudWatch Contributors Insights 規則來檢視身分驗證失敗，而不是使用 CloudWatch Logs** **Insights CloudWatch**。建立類似下列的規則。

```
{
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [
            {
                "Match": "$.activity-type",
                "In": [
                    "AUTH_FAILURE"
                ]
            }
        ],
        "Keys": [
            "$.user"
        ]
    },
    "LogFormat": "JSON",
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupARNs": [
        "arn:aws:logs:us-east-1:999999999999:log-group:/customer/structured_logs"
    ]
}
```

**檢視開啟檔案的日誌項目**

在您的結構化日誌中，檔案讀取日誌項目看起來類似如下：

```
{
  "mode":"READ",
  "path":"/fs-0df669c89d9bf7f45/avtester/example",
  "activity-type":"OPEN",
  "resource-arn":"arn:aws:transfer:us-east-1:999999999999:server/s-0123456789abcdef",
  "session-id":"0049cd844c7536c06a89"
}
```

執行下列查詢，以檢視表示檔案已開啟的日誌項目。

```
filter `activity-type` = 'OPEN'
| display @timestamp, @logStream, `session-id`, mode, path
```