Skip to Content
Hybrid Cloud for Developers
book

Hybrid Cloud for Developers

by Manoj Hirway
April 2018
Intermediate to advanced content levelIntermediate to advanced
280 pages
8h 37m
English
Packt Publishing
Content preview from Hybrid Cloud for Developers

Terminating an EC2 instance in Python

Finally, we can terminate the EC2 instance by instantiating the object of the Instance class by passing the instance-id to its constructor and then invoking the terminate() function of the Instance object. The terminate function starts the termination operation of the specified instance.

The following program is an example of how this can be done using Python:

import boto3ec2 = boto3.resource('ec2')instance = ec2.Instance("i-0f85e284c87db5e70")response = instance.terminate()print response    

The terminate() function returns a Python dictionary that has details of the instance being terminated. This data structure might be needed for reporting purposes. The following is an example of this:

{u'TerminatingInstances': ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hybrid Cloud for Architects

Hybrid Cloud for Architects

Alok Shrivastwa
OpenStack: Building a Cloud Environment

OpenStack: Building a Cloud Environment

Alok Shrivastwa, Sunil Sarat, Kevin Jackson, Cody Bunch, Egle Sigler, Tony Campbell

Publisher Resources

ISBN: 9781788830874Supplemental Content