Reputation: 197
For deployed stack which have have resources marked as "removalPolicy: cdk.RemovalPolicy.RETAIN", cdk destroy - will try to remove these resources AWS console CloudFormation - will give the option to destroy the stack while skipping retain rescues. How can I accomplish this using CDK? How?
Thx
Upvotes: 0
Views: 4384
Reputation: 197
Well, after long conversation with the AWS support team, it appears that adding
currentVersionOptions:{
removalPolicy: cdk.RemovalPolicy.RETAIN
},
into lambda.Function - wont add it into the CloudFromation template. Hence, one should add the following rows at the end of the Lambda creation:
const r = myLambdaFunction.node.defaultChild as cdk.CfnResource;
r.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
Upvotes: 2
Reputation: 41638
As per documentation on RemovalPolicy
RETAIN This uses the 'Retain' DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
In other words after you use cdk destroy
the stack is going to be removed but resources makred with Retain
are going to still exist in your AWS Account.
Upvotes: 0