April 2018
Intermediate to advanced
280 pages
8h 37m
English
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': ...