List All AWS EC2 Instances using boto3.

0 votes

Hi Guys,

I have launched an EC2 instance in AWS. Now I want to list down all the instances using boto3. How can I do that?

Oct 7 in AWS by MD
• 79,390 points
406 views

1 answer to this question.

0 votes

Hi@MD,

You need to import the boto3 module in your script. After you can use this module according to your requirement as shown below

import boto3
 ec2 = boto3.resource('ec2')
 for instance in ec2.instances.all():
     print(
         "Id: {0}\nPlatform: {1}\nType: {2}\nPublic IPv4: {3}\nAMI: {4}\nState: {5}\n".format(
         instance.id, instance.platform, instance.instance_type, instance.public_ip_address, instance.image.id, instance.state
         )
     )
answered Oct 7 by akhtar
• 33,470 points

Related Questions In AWS

+1 vote
2 answers
0 votes
1 answer

List all the existing buckets for the AWS account using Boto3.

Hi@akhtar, You need to create a client using ...READ MORE

answered Oct 7 in AWS by MD
• 79,390 points
30 views
0 votes
1 answer

AWS:Using S3 with EC2 instances

Yes, it can be used for instances ...READ MORE

answered Jun 26, 2018 in AWS by hemant
• 5,800 points
2,283 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

How to create an Internet Gateway using Boto3?

Hi@MD, You can control internet access to the ...READ MORE

answered Oct 10 in AWS by akhtar
• 33,470 points
91 views
0 votes
1 answer

How to create EFS in AWS?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jun 20 in AWS by akhtar
• 33,470 points
138 views