管理 Amazon Config 自定义 Lambda 规则的已删除资源 - Amazon Config
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

管理 Amazon Config 自定义 Lambda 规则的已删除资源

报告已删除资源的规则应返回 NOT_APPLICABLE 的评估结果,以避免不必要的规则评估。

删除资源时,Amazon Config 会创建一个 configurationItemStatusResourceDeleted 的。configurationItem您可以使用此元数据检查规则是否报告了已删除的资源。有关配置项的更多信息,请参阅概念 | 配置项

包括以下代码段以检查是否有已删除的资源,如果报告了已删除的资源,则将 Amazon Config 自定义 Lambda 规则的评估结果设置为 NOT_APPLICABLE

Custom Lambda Rules (Node.js)
// Check whether the resource has been deleted. If the resource was deleted, then the evaluation returns not applicable. function isApplicable(configurationItem, event) { checkDefined(configurationItem, 'configurationItem'); checkDefined(event, 'event'); const status = configurationItem.configurationItemStatus; const eventLeftScope = event.eventLeftScope; return (status === 'OK' || status === 'ResourceDiscovered') && eventLeftScope === false; }
Custom Lambda Rules (Python)
# Check whether the resource has been deleted. If the resource was deleted, then the evaluation returns not applicable. def is_applicable(configurationItem, event): try: check_defined(configurationItem, 'configurationItem') check_defined(event, 'event') except: return True status = configurationItem['configurationItemStatus'] eventLeftScope = event['eventLeftScope'] if status == 'ResourceDeleted': print("Resource Deleted, setting Compliance Status to NOT_APPLICABLE.") return (status == 'OK' or status == 'ResourceDiscovered') and not eventLeftScope
注意

默认情况下,Amazon Config 托管规则和 Amazon Config 自定义策略规则会处理此行为。

如果您将 Python 和 Amazon Config 开发工具包(RDK)与 Amazon Config 开发工具包库(RDKlib)结合使用来创建 Amazon Config 自定义 Lambd 规则,则导入的评估程序类将检查此行为。有关如何使用 RDK 和 RDKlib 编写规则的信息,请参阅使用 RDK 和 RDKlib 编写规则