Is there a way to specify cloudformation stack deletion policy using AWS CDK?

Viewed 936

I have created a VPC using CDK, and now have a need to change the number of subnets and NAT gateways without destroying the (now in production) ec2 instances in it or the (now in production) EIPs that are whitelisted in other systems.

I tried this using CDK and it tried to destroy the VPC and re-provision everything, which is undesirable in production.

Since it is apparently not possible to do what I want by changing the stack definition, I need to get rid of the stack, without removing the VPC.

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.RemovalPolicy.html

I found this document here about a RemovalPoliy enum in CDK, but there is nothing saying where that can be applied. Google searches resulted in only references to S3 and RDS, even though this enum is in CDK core. I tried applying it to the following CDK resources: stack, vpc, security group, etc, but none of those constructs accept the removalPolicy parameter.

eg:

const vpc = new ec2.Vpc(this, 'PRODVPC', {
  maxAzs: 2,
  removalPolicy: cdk.RemovalPolicy.RETAIN
});

new VPCPRODStack(app, 'RDVPCPRODStack', {
  env: {region: 'ca-central-1', account: '12345'},
  removalPolicy: cdk.RemovalPolicy.RETAIN
});


What am I missing? Is it even possible to set a cloudformation removal policy using CDK at the stack level?

0 Answers
Related