amazon-web-servicesamazon-ec2aws-cdk

How to enable EC2 Instance termination protection in AWS CDK?


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