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, 2020 in AWS by MD
• 95,460 points
30,686 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
         )
     )

Get ready to level up your skills as an AWS Developer! Join our comprehensive AWS Developer Associate certification Course!

answered Oct 7, 2020 by akhtar
• 38,260 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 8, 2020 in AWS by MD
• 95,460 points
1,615 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,790 points
6,305 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, 2020 in AWS by akhtar
• 38,260 points
1,505 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, 2020 in AWS by akhtar
• 38,260 points
898 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP