The code imports the boto3 library. Next, it creates an instance of the EC2 object. Finally, it calls the describe_instances() method on the EC2 object, passing in the instance as the first argument.
The describe_instances() method returns a dictionary containing information about the specified instance. In this case, the method returns a dictionary containing the following keys:
Name: The name of the instance
State: The state of the instance
AMI: The Amazon Elastic Compute Cloud (Amazon EC2) instance ID
availability_zone: The Availability Zone the instance is located in
region: The region of the world where the instance is located
ami_id: The Amazon Elastic Compute Cloud (Amazon EC2) instance ID
The list of attributes returned by the describe_instances() method is broad, but some of the more important attributes include the name, state, availability zone, and region of the instance.
import boto3 import boto3 ec2 = boto3.client('ec2') response = ec2.describe_instances()