當我的 ACM 匯入憑證即將到期時,如何收到通知?
上次更新日期:2022 年 7 月 19 日
我匯入了 AWS Certificate Manager (ACM) 憑證。我想在憑證到期前重新匯入憑證。如何在匯入的憑證到期前收到通知?
簡短描述
ACM 不會為匯入的憑證提供受管續約。若要續約匯入的憑證,請先向憑證簽發者請求新憑證。然後,手動將憑證重新匯入 ACM。
解決方案
您可以使用 AWS Config 檢查是否有接近到期日的憑證。當憑證接近到期日時,您也可以使用 Amazon EventBridge 接收電子郵件通知。
注意:
- 啟用 AWS Config 會根據用量而產生額外的費用。如需詳細資訊,請參閱 AWS Config 定價。
- 在設定 AW Config 規則之前,請確定已建立 Amazon Simple Notification Service (Amazon SNS) 主題和 Amazon EventBridge 規則。這樣做可確保所有不合規的憑證均會在到期日之前觸發通知。
建立 EventBridge 規則
搭配 EventBridge 規則使用自訂事件模式,以符合 AWS Config 受管規則 acm-certificate-expiration-check。然後,將回應路由傳送至 Amazon Simple Notification Service 主題。
1. 如果您尚未建立 Amazon SNS 主題,請依照 Amazon SNS 入門的指示來操作。
注意:Amazon SNS 主題必須與您的 AWS Config 服務位於相同區域。
2. 開啟 EventBridge 主控台,然後選擇 Rules (規則)。
3. 選擇 Create rule (建立規則)。
4. 在 Name (名稱) 中,輸入您的規則名稱。
5. 在 Rule type (規則類型) 中,選取 Rule with and event pattern (包含事件模式的規則),然後選擇 Next (下一步)。
6. 在 Event source (事件來源) 中,請選擇 AWS events or EventBridge partner events (AWS 事件或 EventBridge 合作夥伴事件)。
7. 在 Event pattern (事件模式) 中,選擇 Custom patterns (JSON editor) (自訂模式 (JSON 編輯器))。
8. 在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"
}
14. 在 Input Template (輸入範本) 文字方塊中,複製並貼上下列範本:
"On <time> AWS Config rule <rule> evaluated the <resourceType> with Id <resourceId> in the account <awsAccountId> region <awsRegion> as <compliance>."
"For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=<awsRegion>#/timeline/<resourceType>/<resourceId>/configuration."
15. 選擇 Confirm 確認、Next 下一步、Next 下一步、Create rule建立規則。
16. 如果事件類型啟動,您會收到 SNS 電子郵件通知,其中包含填入了來自步驟 14 的內容之自訂欄位,類似下列內容:
"On ExampleTime AWS Config rule ExampleRuleName evaluated the ExampleResourceType with Id ExampleResource_ID in the account ExampleAccount_Id in Region ExampleRegion as ExamplecomplianceType.
For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=ExampleRegion#/timeline/ExampleResourceType/ExampleResource_ID/configuration"
建立 AWS Config 規則
1. 開啟 AWS Config 主控台,選擇 Rules (規則),然後選擇 Add rule (新增規則)。
2. 在 Select rule type (選取規則類型) 中,選擇 Add AWS managed rule (新增 AWS 受管規則)。
3. 在 AWS Managed Rules (AWS 受管規則) 中,選擇 acm-certificate-expiration-check,然後選擇 Next (下一步)。
4. 在 Parameters (參數) 中,對於 daysToExpiration 索引鍵,在 Value (值) 中,輸入您希望規則在到期前觸發的天數。
5. 選擇 Next (下一步),然後選擇 Add rule (新增規則)。
對於即將到期的憑證,AWS Config 規則 acm-certificate-expiration-check 會從在步驟 4 中輸入的天數起即標記為 Noncompliant (不合規)。