O'Reilly logo

Programming Amazon Web Services by James Murty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controlling Instances

The EC2 service provides API operations for managing the lifecycle of your instances. We will start by looking at how you can terminate your running instances; it is wise to know how to do this before you start launching instances that will incur fees for every hour they run.

Stop Running Instances

The TerminateInstances operation shown in Table 5-10 terminates one or more instances running in your EC2 account. An instance can be terminated multiple times without any ill effects.

Table 5-10. TerminateInstances request parameters

Parameter NameValueRequired?
ActionTerminateInstancesYes
InstanceId (Indexed)The identifiers of one or more instances to terminateYes

Here is an XML document returned by the operation:

<TerminateInstancesResponse 
                          xmlns='http://ec2.amazonaws.com/doc/2007-08-29/'>
  <instancesSet>
    <item>
      <instanceId>i-ec43a885</instanceId>
      <shutdownState>
        <code>32</code>
        <name>shutting-down</name>
      </shutdownState>
      <previousState>
        <code>16</code>
        <name>running</name>
      </previousState>
    </item>
  </instancesSet>
</TerminateInstancesResponse>

The response document returned by the operation includes a listing of the instances that were acted upon by the operation with information about the instance’s prior status and its status as a result of the TerminateInstances operation. Each item element in the XML document describes the status of one instance, Table 5-11 lists the contents of this element.

Table 5-11. TerminateInstancesResponseInfoType element

Element NameDescription ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required