Amazon Elastic Compute Cloud
User Guide (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Enabling Termination Protection for an Instance

The following information applies to instances of Amazon EBS-backed AMIs or Amazon EC2 instance store-backed AMIs.

By default, any instances you launch can be externally terminated from the console, command line, or API. If you want to prevent accidental external termination of the instance, you can enable termination protection for the instance.

Important

Instances that are part of an Auto Scaling group are not covered by termination protection. For more information, see Instance Termination Policy for Your Auto Scaling Group in the Auto Scaling Developer Guide.

The instance's DisableApiTermination attribute controls whether the instance is protected from external termination. A value of true means the instance is protected and can't be externally terminated; a value of false means it's not protected and can be externally terminated. You can specify whether an instance is protected either at launch time or after the instance is running. You can modify this attribute while the instance is running or stopped (for Amazon EBS-backed instances).

Note

The DisableApiTermination attribute does not protect an instance from being terminated by being shutdown from within the instance when the InstanceInitiatedShutdownBehavior attribute is set for the instance. For more information about the InstanceInitiatedShutdownBehavior attribute, see Changing the Instance Initiated Shutdown Behavior.

AWS Management Console

By default, termination protection is disabled for an instance at launch time.

To enable termination protection for an instance at launch time

  • In the Request Instances Wizard, select the check box for Termination Protection.

    Instance launch wizard: termination protection

To enable termination protection for an instance after it's launched

  1. In your list of instances, right-click the instance and select Change Termination Protection.

    A confirmation dialog box appears with the current status of termination protection.

  2. Click Yes, Enable.

    Now the instance cannot be terminated until you disable termination protection.

You can use the same procedure to disable termination protection for the instance. You can enable and disable this attribute of an instance as often as you want.

Command Line Tools

By default, termination protection is disabled for an instance at launch time.

To enable termination protection for an instance at launch time

  • Add --disable-api-termination to the ec2-run-instances command.

    PROMPT>  ec2-run-instances ami_id --disable-api-termination ...

To enable termination protection for an instance after it's launched

  1. View the current value for the attribute with the following command.

    PROMPT>  ec2-describe-instance-attribute instance_id --disable-api-termination

    The following is a sample response.

    disableApiTermination   i-87ad5eec      false
  2. Enable termination protection with the following command.

    PROMPT>  ec2-modify-instance-attribute instance_id --disable-api-termination true

    The following is a sample response.

    disableApiTermination   i-87ad5eec      true

To disable termination protection for an instance

  • Disable termination protection for the instance with the following command.

    PROMPT>  ec2-modify-instance-attribute instance_id --disable-api-termination false

    The following is a sample response.

    disableApiTermination   i-87ad5eec      false

You can enable and disable this attribute of an instance as often as you want.

API

By default, termination protection is disabled for an instance at launch time.

To enable termination protection for an instance at launch time

  • Issue a Query request for RunInstances similar to the following example and include DisableApiTermination=true.

    https://ec2.amazonaws.com/?Action=RunInstances
    &ImageId=ami-60a54009
    &MaxCount=3
    &MinCount=1
    &DisableApiTermination=true
    &Placement.AvailabilityZone=us-east-1b
    &Monitoring.Enabled=true
    &AUTHPARAMS

    For information about AUTHPARAMS, see Common Query Parameters in the Amazon Elastic Compute Cloud API Reference.

To enable termination protection for an instance after it's launched

  1. Issue the following Query request to get the current value of the disableApiTermination attribute.

    https://ec2.amazonaws.com/
    ?Action=DescribeInstanceAttribute
    &InstanceId=i-87ad5eec
    &Attribute=disableApiTermination
    &AUTHPARAMS

    The following is an example response.

    <DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
       <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> 
       <instanceId>i-87ad5eec</instanceId>
       <disableApiTermination>
          <value>false</value>
       </disableApiTermination>
    </DescribeInstanceAttributeResponse>
  2. Issue the following Query request to modify the disableApiTermination attribute.

    https://ec2.amazonaws.com/
    ?Action=ModifyInstanceAttribute
    &InstanceId=i-87ad5eec
    &DisableApiTermination.Value=true
    &AUTHPARAMS

    The following is an example response.

    <ModifyInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
       <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> 
       <return>true</return>
    </ModifyInstanceAttributeResponse>

To disable termination protection for an instance

  • Issue the following Query request to modify the disableApiTermination attribute.

    https://ec2.amazonaws.com/
    ?Action=ModifyInstanceAttribute
    &InstanceId=i-87ad5eec
    &DisableApiTermination.Value=false
    &AUTHPARAMS

    The following is an example response.

    <ModifyInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
       <return>true</return>
    </ModifyInstanceAttributeResponse>

You can enable and disable this attribute of an instance as often as you want.