is there some way to set `removalPolicy` to `DESTR...
# help
s
is there some way to set
removalPolicy
to
DESTROY
for all resources in a stack? one of the nice things about CloudFormation is the cleanup.. and setting
RETAIN
as default for many resources defeats that purpose
f
Hey @Sam Hulick, you mean things like S3 buckets, DynamoDB tables, CloudWatch LogGroups primarily right?
s
KMS keys, Cognito pools as well, are retain by default
f
you know what.. that’s a great idea for a high level flag on the
<http://sst.App|sst.App>
or
sst.Stack
, to set
removalPolicy
for all resources.
s
yeah, I was looking for that actually!
f
For now, you can loop through each CFN resource and set the flag. Something like:
Copy code
stack.node.children.forEach(resource => {
  resource = resource as cdk.CfnResource;
  resource.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);
});
s
ahh, neat trick. thanks!
f
I haven’t tested the code above, but give it a try
Got the idea from the last code snippet in this doc https://docs.aws.amazon.com/cdk/latest/guide/resources.html
s
still learning the ropes of CDK. it’s so powerful