

# REL06-BP03 傳送通知 (即時處理和警示)
<a name="rel_monitor_aws_resources_notification_monitor"></a>

當組織偵測到潛在問題時，他們會將即時通知和警示傳送給適當的人員和系統，以便快速有效地應對這些問題。

 **預期成果：**根據服務和應用程式指標設定相關警示，就可以快速回應操作事件。違反警示閾值時，系統會通知適當的人員和系統，以便解決潛在問題。

 **常見的反模式：**
+ 將警示的閾值設得過高，會導致無法傳送重要通知。
+ 將警示的閾值設得太低，導致使用者因通知過多的干擾而無法針對重要提醒採取行動。
+  當使用情況改變時，未更新警示及其閾值。
+  針對透過自動化動作解決的最佳警示，將通知傳送給人員而未引發自動化動作，會導致傳送過多的通知。

 **建立此最佳實務的優勢：**將即時通知和警示傳送給適當的人員和系統，以便及早發現問題並快速回應操作事故。

 **未建立此最佳實務時的曝險等級：**高 

## 實作指引
<a name="implementation-guidance"></a>

 工作負載應具備即時處理和警示功能，以改善可能影響應用程式可用性問題的可偵測性，並作為自動化回應的觸發程式。組織可以透過使用已定義的指標建立警示來執行即時處理和警示，以便在發生重大事件或指標超過閾值時收到通知。

 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 可讓您根據靜態閾值、異常偵測和其他條件，使用 CloudWatch 警示來建立[指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html)和複合警示。如需有關可使用 CloudWatch 來設定的警示類型的詳細資訊，請參閱 [CloudWatch 文件的警示一節](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)。

 您可以使用 [CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)為團隊建構 AWS 資源的指標和警示的自訂檢視。CloudWatch 主控台中的可自訂首頁可讓您在單一檢視中監控多個區域的資源。

 警示可執行一個或多個動作，例如向 [Amazon SNS 主題](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)傳送通知、執行 [Amazon EC2](https://aws.amazon.com/ec2/) 動作或 [Amazon EC2 Auto Scaling](https://aws.amazon.com/ec2/autoscaling/) 動作，或在 AWS Systems Manager 中建立 [OpsItem](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter-create-OpsItems-from-CloudWatch-Alarms.html) 或[事故](https://docs.aws.amazon.com/incident-manager/latest/userguide/incident-creation.html)。

 Amazon CloudWatch 使用 [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 於警示變更狀態時傳送通知，將訊息傳遞從發布者 (生產者) 提供給訂閱用戶 (消費者)。如需有關設定 Amazon SNS 通知的詳細資訊，請參閱 [Configuring Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/sns-configuring.html)。

 每當建立、更新、刪除 CloudWatch 警示或變更其狀態時，CloudWatch 就會傳送 [EventBridge](https://aws.amazon.com/eventbridge/) [事件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-and-eventbridge.html)。您可以使用 EventBridge 搭配這些事件來建立執行動作的規則，例如，當警示狀態變更時就通知您，或使用 [Systems Manager Automation](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html) 自動觸發您帳戶中的事件。

 利用 [AWS Health](https://aws.amazon.com/premiumsupport/technology/aws-health/) 隨時掌握新知。AWS Health 是 AWS 雲端 資源運作狀態的權威資訊來源。使用 AWS Health 來接收任何已確認服務事件的通知，方便您快速採取行動來緩解任何影響。透過 [AWS 使用者通知](https://docs.aws.amazon.com/notifications/latest/userguide/what-is-service.html) 建立符合用途的 AWS Health 事件通知，以利用電子郵件和聊天管道傳送，並透過 [Amazon EventBridge 以程式設計方式與您的監控和警示工具](https://docs.aws.amazon.com/health/latest/ug/cloudwatch-events-health.html)整合。如果使用 AWS Organizations，則跨帳戶彙總 AWS Health 事件。

**應何時使用 EventBridge 或 Amazon SNS？**

 EventBridge 和 Amazon SNS 可用於開發事件驅動的應用程式，將視具體需求來做出選擇。

 當您想要建立應用程式以回應您自己的應用程式、SaaS 應用程式和 AWS 服務中的事件時，建議使用 Amazon EventBridge。EventBridge 是唯一可直接與第三方 SaaS 合作夥伴整合的事件型服務。EventBridge 也會自動擷取來自 200 多個 AWS 服務的事件，而不需要開發人員在其帳戶中建立任何資源。

 EventBridge 會將已定義的 JSON 架構用於事件，並協助您建立在整個事件內文中套用的規則，以選取要轉寄至[目標](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html)的事件。EventBridge 目前支援超過 20 種 AWS 服務作為目標，包括 [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)、[Amazon SQS](https://aws.amazon.com/sqs/)、Amazon SNS、[Amazon Kinesis Data Streams](https://aws.amazon.com/kinesis/data-streams/) 和 [Amazon Data Firehose](https://aws.amazon.com/kinesis/data-firehose/)。

 針對需要高散發的應用程式 (數千或數百萬個端點)，建議使用 Amazon SNS。我們看到的常見模式是客戶使用 Amazon SNS 做為規則的目標，以篩選所需的事件並散發到多個端點。

 訊息是非結構化的，可以是任何格式。Amazon SNS 支援將訊息轉寄到六種不同類型的目標，包括 Lambda、Amazon SQS、HTTP/S 端點、SMS、行動推送和電子郵件。Amazon SNS [一般的延遲時間短於 30 毫秒](https://aws.amazon.com/sns/faqs/)。透過將服務設定為傳送 Amazon SNS 訊息，各種 AWS 服務就能做到這一點 (超過 30 個，包括 Amazon EC2、[Amazon S3](https://aws.amazon.com/s3/) 和 [Amazon RDS](https://aws.amazon.com/rds/))。

### 實作步驟
<a name="implementation-steps"></a>

1.  使用 [Amazon CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)建立警示。

   1.  指標警示會監控單一 CloudWatch 指標或與 CloudWatch 指標相依的表達式。與超過一段時間間隔的閾值相比，警示會根據指標或表達式的值起始一或多個動作。該動作可能包含將通知傳送至 [Amazon SNS 主題](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)、執行 [Amazon EC2](https://aws.amazon.com/ec2/) 動作或 [Amazon EC2 Auto Scaling](https://aws.amazon.com/ec2/autoscaling/) 動作，或在 AWS Systems Manager 中[建立 OpsItem](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter-create-OpsItems-from-CloudWatch-Alarms.html) 或[事故](https://docs.aws.amazon.com/incident-manager/latest/userguide/incident-creation.html)。

   1.  複合警示由規則表達式組成，該規則表達式會將您已建立的其他警示條件納入考量。只有在符合所有規則條件時，複合警示才會進入警示狀態。在複合警示規則表達式中指定的警示可能會包括指標警示和其他複合警示。複合警示可以在變更狀態時傳送 Amazon SNS 通知，並且可以在進入警示狀態時建立 Systems Manager [OpsItems](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter-create-OpsItems-from-CloudWatch-Alarms.html) 或[事故](https://docs.aws.amazon.com/incident-manager/latest/userguide/incident-creation.html)，但無法執行 Amazon EC2 動作或 Auto Scaling 動作。

1.  設定 [Amazon SNS 通知](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)。建立 CloudWatch 警示時，可以包含 Amazon SNS 主題，以便在警示變更狀態時傳送通知。

1.  [在 EventBridge 中建立](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-get-started.html)符合指定 CloudWatch 警示的規則。每個規則都支援多個目標，包括 Lambda 函數。例如，您可以定義在可用磁碟空間不足時啟動的警示，該警示會透過 EventBridge 規則觸發 Lambda 函數以清理空間。如需有關 EventBridge 目標的詳細資訊，請參閱 [EventBridge targets](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html)。

## 資源
<a name="resources"></a>

 **相關 Well-Architected 的最佳實務：**
+  [REL06-BP01 監控工作負載的所有元件 (產生)](rel_monitor_aws_resources_monitor_resources.md) 
+  [REL06-BP02 定義和計算指標 (彙總)](rel_monitor_aws_resources_notification_aggregation.md) 
+  [REL12-BP01 使用程序手冊調查失敗](rel_testing_resiliency_playbook_resiliency.md) 

 **相關文件：**
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)
+ [CloudWatch Logs 洞察](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)
+  [使用 Amazon CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) 
+  [使用 Amazon CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html) 
+  [使用 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html) 
+ [設定 Amazon SNS 通知](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)
+ [CloudWatch 異常偵測](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Anomaly_Detection.html)
+ [CloudWatch Logs 資料保護](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/protect-sensitive-log-data-types.html)
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html)
+ [Amazon Simple Notification Service](https://aws.amazon.com/sns/)

 **相關影片：**
+ [重塑 2022 年可觀測性影片](https://www.youtube.com/results?search_query=reinvent+2022+observability)
+ [AWS re:Invent 2022 - Amazon 的可觀測性最佳實務](https://www.youtube.com/watch?v=zZPzXEBW4P8)

 **相關範例：**
+  [一個可觀測性研討會](https://observability.workshop.aws/) 
+ [Amazon EventBridge 到 AWS Lambda，由 Amazon CloudWatch 警示進行回饋控制](https://serverlessland.com/patterns/cdk-closed-loop-serverless-control-pattern)