Managing AWS instances
Now, we're ready to create our first virtual machine using boto3
. As we have discussed, we need the AMI that we will instantiate an instance from. Think of an AMI as a Python class; creating an instance will create an object from it. We will use the Amazon Linux AMI, which is a special Linux operating system maintained by Amazon and used for deploying Linux machines without any extra charges. You can find a full AMI ID, per region, at https://aws.amazon.com/amazon-linux-ami/:

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='ami-824c4ee2', MinCount=1, MaxCount=1, InstanceType='m5.xlarge', Placement={'AvailabilityZone': 'us-west-2'}, ) print(instance[0])
In the preceding example, the following applies:
- We imported the
boto3
module that we installed previously. - Then, we specified a resource type that we wanted to interact with, which is EC2, and assigned that to the
ec2
object.
- Now, we are eligible to use the
create_instance()
method and...