June 2018
Intermediate to advanced
398 pages
9h
English
The printed ID is used in CRUD operations to manage or terminate the instance later. For example, we can terminate the instance by using the terminate() method also provided to the ec2 resource created earlier:
import boto3ec2 = boto3.resource('ec2')instance_id = "i-0a81k3ndl29175220"instance = ec2.Instance(instance_id)instance.terminate()
Notice that we hardcoded instance_id in the preceding code (which is not always the case when you need to create a dynamic Python script that can be used in different environments). We can use other input methods that are available in Python, such as raw_input(), to take the input from the user or query the available instances in our accounts and make Python prompt us on which instances ...
Read now
Unlock full access