File size: 1,772 Bytes
b40c49c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from __future__ import annotations
from typing import Any
import cfnlint.data.schemas.other.resources as resources_schemas
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails
class UpdateReplacePolicyDeletionPolicy(CfnLintJsonSchema):
"""Check resources with UpdateReplacePolicy/DeletionPolicy have both"""
id = "W3011"
shortdesc = "Check resources with UpdateReplacePolicy/DeletionPolicy have both"
description = (
"Both UpdateReplacePolicy and DeletionPolicy are needed to protect resources"
" from deletion"
)
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html"
tags = ["resources", "updatereplacepolicy", "deletionpolicy"]
def __init__(
self,
) -> None:
super().__init__(
["Resources/*"],
SchemaDetails(resources_schemas, "update_policy_delete.json"),
False,
)
def message(self, instance: Any, err: ValidationError) -> str:
return (
"Both 'UpdateReplacePolicy' and 'DeletionPolicy' "
"are needed to protect resource from deletion"
)
def validate(
self, validator: Validator, keywords: Any, instance: Any, schema: dict[str, Any]
) -> ValidationResult:
resource_type = instance.get("Type")
if resource_type in [
"AWS::Lambda::Version",
"AWS::Lambda::LayerVersion",
]:
return
yield from super().validate(validator, keywords, instance, schema)
|