[SOLVED] How to enable EC2 Instance termination protection in AWS CDK?

Issue

This Content is from Stack Overflow. Question asked by tom10271

enter image description here

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Instance.html

I cannot find anything related to it. I guess I need to use L1 construct?



Solution

Yes, you will have to use the L1 construct: CfnInstance.

This construct has the disableApiTermination prop which can be set to true to enable termination protection.

disableApiTermination?
Type: boolean | IResolvable (optional)

If you set this parameter to true , you can’t terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can.

Default: false


This Question was asked in StackOverflow by tom10271 and Answered by Ermiya Eskandary It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?