跳至內容

當我的 ACM 匯入憑證即將到期時,該如何收到通知?

4 分的閱讀內容
0

我已匯入 AWS Certificate Manager (ACM) 憑證,並希望在憑證到期前收到提醒以重新匯入該憑證。

簡短說明

若要在您的憑證即將到期時收到通知,請使用以下其中一種方法:

根據預設,ACM Certificate Approaching Expiration 事件會在事件到期前 45 天傳送通知。您可以變更天數,但不可超過 45 天。若要設定事件到期前 45 天以上的通知,請使用自訂 EventBridge 規則或 CloudWatch 警示。

解決方法

在 EventBridge 中設定 ACM Certificate Approaching Expiration 事件

**先決條件:**如果您沒有 Amazon Simple Notification Service (Amazon SNS) 主題,請建立主題

請完成以下步驟:

  1. 開啟 EventBridge console (EventBridge 主控台)。
  2. 在導覽窗格中,選擇 Rules (規則),然後選擇 Create rule (建立規則)。
  3. 為您的規則輸入 Name (名稱)。
    **注意:**您必須為位於相同 AWS Region 且在相同事件匯流排上的規則,指定唯一名稱。
  4. Event bus (事件匯流排),選取事件匯流排。若要讓規則與來自您 AWS 帳戶的事件相符,請選取 AWS default event bus (AWS 預設事件匯流排),使事件傳送至您帳戶的預設事件匯流排。
  5. Rule type (規則類型),選擇 Rule with an event pattern (具有事件模式的規則),然後選擇 Next (下一步)。
  6. Event source (事件來源),選擇 AWS events or EventBridge partner events (AWS 事件或 EventBridge 合作夥伴事件)。
  7. Creation method (建立方法),選擇 Use pattern form option (使用模式表單選項)。
  8. Event pattern (事件模式) 區段中,完成以下步驟:
    Event source (事件來源),選擇 AWS Services (AWS 服務)。
    AWS service (AWS 服務),選擇 Certificate Manager
    Event type (事件類型),選擇 ACM Certificate Approaching Expiration (ACM 憑證即將到期)。
  9. 選擇 Next (下一步)。
  10. Target types (目標類型),選擇 AWS Service (AWS 服務)。
  11. Select a target (選取目標),選擇 SNS topic (SNS 主題),然後選取 Amazon SNS 主題。
  12. 選擇 Next (下一步)。
  13. (選用) 新增標籤。
  14. 選擇 Next (下一步)。
  15. 檢閱規則詳細資訊,然後選擇 Create rule (建立規則)。

建立規則後,您可以變更接收到期通知的日期。在 PutAccountConfiguration ACM API 操作中,為 DaysBeforeExpiry 輸入 1 至 45 之間的值。

建立自訂 EventBridge 規則和 AWS Config 規則

**先決條件:**如果您沒有 Amazon SNS 主題,請建立主題

使用自訂事件模式搭配 EventBridge 規則,以符合 acm-certificate-expiration-check AWS Config 受管規則。然後,將回應路由至 Amazon SNS 主題。 Amazon SNS 主題必須與您的 AWS Config 服務位於相同 AWS Region。

**注意:**使用 AWS Config 時,會產生費用。如需更多資訊,請參閱 AWS Config 定價

建立 EventBridge 規則

請完成以下步驟:

  1. 開啟 EventBridge console (EventBridge 主控台)。

  2. 選擇 Rules (規則),然後選擇 Create rule (建立規則)。

  3. Name (名稱) 中,為您的規則輸入名稱。

  4. Rule type (規則類型) 中,選擇 Rule with and event pattern (具有事件模式的規則),然後選擇 Next (下一步)。

  5. Event source (事件來源),選擇 AWS events or EventBridge partner events (AWS 事件或 EventBridge 合作夥伴事件)。

  6. Event pattern (事件模式) 中,選擇 Custom patterns (JSON editor) (自訂模式 (JSON 編輯器))。

  7. Event pattern (事件模式) 預覽窗格中,輸入以下事件模式:

    {  "source": [    "aws.config"
      ],
      "detail-type": [
        "Config Rules Compliance Change"
      ],
      "detail": {
        "messageType": [
          "ComplianceChangeNotification"
        ],
        "configRuleName": [
          "acm-certificate-expiration-check"
        ],
        "resourceType": [
          "AWS::ACM::Certificate"
        ],
        "newEvaluationResult": {
          "complianceType": [
            "NON_COMPLIANT"
          ]
        }
      }
    }
  8. 選擇 Next (下一步)。

  9. Select a target (選取目標) 中,選擇 SNS topic (SNS 主題)。

  10. Topic (主題) 中,選取您的 SNS 主題。

  11. Configure target input (設定目標輸入) 下拉式清單中,選擇 Input transformer (輸入轉換器)。

  12. 選擇 Configure input transformer (設定輸入轉換器)。

  13. Input path (輸入路徑) 文字方塊中,輸入以下路徑:

{  "awsRegion": "$.detail.awsRegion",  "resourceId": "$.detail.resourceId",
  "awsAccountId": "$.detail.awsAccountId",
  "compliance": "$.detail.newEvaluationResult.complianceType",
  "rule": "$.detail.configRuleName",
  "time": "$.detail.newEvaluationResult.resultRecordedTime",
  "resourceType": "$.detail.resourceType"
}
  1. Template (範本) 文字方塊中,輸入以下範本:
"On example_time AWS Config rule example_rule evaluated the example_resourceType with Id example_resourceId in the account example_awsAccountId region example_awsRegion as example_compliancetype.""For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=awsRegion#/timeline/resourceType/resourceId/configuration."

**注意:**請將範例值替換為您的值。 選擇 Confirm (確認),然後選擇 Next (下一步)。 再次選擇 Next (下一步),然後選擇 Create rule (建立規則)。

如果 ACM 啟用事件類型,那麼您會收到 SNS 電子郵件通知。

建立 AWS Config 規則

若要建立 AWS Config 規則,請完成以下步驟:

  1. 開啟 AWS Config console (AWS Config 主控台)。
  2. 在導覽窗格中,選擇 Rules (規則),然後選擇 Add rule (新增規則)。
  3. Select rule type (選取規則類型) 中,選擇 Add AWS managed rule (新增 AWS 受管規則)。
  4. AWS Managed Rules (AWS 受管規則) 中,選擇 acm-certificate-expiration-check,然後選擇 Next (下一步)。
  5. Parameters (參數) 頁面上,於 Value (值) 中,在 daysToExpiration 索引鍵輸入您希望規則調用的天數。
    **注意:**如果憑證在您輸入的天數內接近到期日,則 acm-certificate-expiration-check 規則會將該規則識別為 NON_COMPLIANT
  6. 選擇 Next (下一步),然後選擇 Add rule (新增規則)。

根據靜態閾值建立 CloudWatch 警示

請完成以下步驟:

  1. 開啟 CloudWatch console (CloudWatch 主控台)。
  2. 在導覽窗格中,選擇 Alarms (警示),然後選擇 All alarms (所有警示)。
  3. 選擇 Create alarm (建立警示),然後選擇 Select metric (選取指標)。
  4. 選擇 Certificate Manager,然後選擇 Certificate Metrics (憑證指標)。
  5. Metrics (指標) 頁面上,選取指標,然後選擇 Select metric (選取指標)。
  6. Specify metric and conditions (指定指標與條件) 頁面上,於 Statistic (統計) 中選擇 Minimum (最小值)。
  7. Period (期間) 中,選擇 1 day (1 天)。
  8. Whenever DaysToExpiry is... (當 DaysToExpiry 為...) 中,選擇 Lower/Equal (小於/等於),然後將 than... (值...) 設為您希望在到期前執行警示的天數。
  9. 選擇 Next (下一步)。
  10. Notification (通知) 中,選擇 In alarm (處於警示狀態時)。
  11. Send a notification to the following SNS topic (將通知傳送至以下 SNS 主題) 中,選擇 Select an existing SNS topic (選取現有 SNS 主題) 或 Create new topic (建立新主題),然後選擇 Next (下一步)。
  12. 輸入警示名稱,選擇 Next (下一步)。
  13. 選擇 Create alarm (建立警示)。

如需更多資訊,請參閱 根據靜態閾值建立 CloudWatch 警示

相關資訊

重新匯入憑證

開始使用 AWS Certificate Manager 憑證

如何使用 AWS Config 在 AWS 資源不符合規範時收到通知?

AWS Config 的安全性最佳實務

AWS 官方已更新 5 個月前