CDK Mixin for Deletion Protection
Introduction This post builds on the AWS CDK Ephemeral Stacks Cleanup pattern and focuses on permanent environments. For permanent stacks, the goal is to couple CDK removal policies with CloudForma...

Source: DEV Community
Introduction This post builds on the AWS CDK Ephemeral Stacks Cleanup pattern and focuses on permanent environments. For permanent stacks, the goal is to couple CDK removal policies with CloudFormation deletion protection so critical resources are harder to delete by accident. Mixin A CDK mixin applies cross-cutting behavior across many constructs from one place. This DeletionProtectionMixin sets stack-level termination protection and, for selected CloudFormation resources, enables deletion protection only when a retain-style removal policy is present. The mapping in applyTo follows CloudFormation property names: Stack.terminationProtection for stacks deletionProtectionEnabled for AWS::Logs::LogGroup and AWS::DynamoDB::Table deletionProtection for supported RDS, DocumentDB, and Neptune resources By checking hasRetainRemovalPolicy first, the mixin keeps lifecycle intent aligned: resources marked to be retained also get deletion-protection settings where the service supports them. import