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...

Changing the Instance Initiated Shutdown Behavior

By default, when you initiate a shutdown from within an EBS-backed instance, the instance stops. You can change this so the instance terminates instead. You just modify the InstanceInitiatedShutdownBehavior attribute for the instance. You can do this while the instance is either running or stopped.

Note

This termination process will occur no matter what the DisableApiTermination attribute is set to. For more information about the DisableApiTermination attribute, see Enabling Termination Protection for an Instance.

Caution

When an AMI is created from an instance, the InstanceInitiatedShutdownBehavior attribute for the instance is also stored in the AMI. Any instances created from that AMI will inherit the InstanceInitiatedShutdownBehavior attribute. This can result in instances being inadvertently terminated when they are shut down from within the instance. You cannot change this attribute in the AMI, but you can change it in the launched instance. The best practice is to always set the InstanceInitiatedShutdownBehavior attribute of an instance to stop before creating an AMI from the instance.

AWS Management Console

To change the Shutdown Behavior

  1. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. Click Instances in the navigation pane.

  3. Context-click on the instance you want to modify and select Change Shutdown Behavior.

  4. Select either Terminate or Stop from the Shutdown Behavior drop-down list.

    Change Shutdown Behavior dialog box

  5. Click Yes, Change.

You can toggle the attribute between Stop and Terminate as often as you want.

Command Line tools

To change the instance-initiated-shutdown-behavior attribute

  1. View the current value for the attribute with the ec2-describe-instance-attribute command.

    PROMPT>  ec2-describe-instance-attribute instance_id --instance-initiated-shutdown-behavior

    Sample response:

    instanceInitiatedShutdownBehavior      i-87ad5eec      stop
  2. Change the attribute value to terminate with the ec2-modify-instance-attribute command.

    PROMPT>  ec2-modify-instance-attribute instance_id --instance-initiated-shutdown-behavior terminate

    Sample response:

    instanceInitiatedShutdownBehavior      i-87ad5eec      terminate

You can toggle the attribute between stop and terminate as often as you want.

API

To change the InstanceInitiatedShutdownBehavior attribute

  1. Call the DescribeInstanceAttribute action to get the current value of the attribute.

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

    For information about the auth parameters, see Common Query Parameters in the Amazon EC2 API Reference.

    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-5d7e8e36</instanceId>
       <instanceInitiatedShutdownBehavior>
          <value>stop</value>
       </instanceInitiatedShutdownBehavior>
    </DescribeInstanceAttributeResponse>
  2. Call the ModifyInstanceAttribute action to change the attribute's value.

    https://ec2.amazonaws.com/
    ?Action=ModifyInstanceAttribute
    &InstanceId=i-87ad5eec
    &Attribute=instanceInitiatedShutdownBehavior
    &Value=terminate
    &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>

You can toggle the attribute between stop and terminate as often as you want.