Python code to list all the running EC2 instances across all regions in an AWS account

This code snippet will help you to get the list of all running EC2 instances across all regions in an AWS account. I have used python boto3 package for developing the code. This code will dynamically pick up all the aws ec2 regions. So the code will work perfectly without any modification even if a new region gets added to the AWS.

Note: Only the basic api calls just to list the instance details are mentioned in this program . Proper coding conventions are not followed . 🙂


Generate the AWS Access Key and Secret Access Key from the AWS console (IAM section). This code will be helpful to quickly find the summary of all the EC2 instances across regions.

About amalgjose
I am an Electrical Engineer by qualification, now I am working as a Software Architect. I am very much interested in Electrical, Electronics, Mechanical and now in Software fields. I like exploring things in these fields. I love travelling, long drives and music.

12 Responses to Python code to list all the running EC2 instances across all regions in an AWS account

  1. Somappa Hadoop says:


  2. Banchy says:

    This is great.
    Could you please advice how to add also Tag name in this script so it returns the Name of EC2 instance?

    • amalgjose says:

      The API has changed. The one I used in this code is with respect to boto2. Now it is boto3. Please refer to the boto3 docs for more details. Let me know if you face any issues.

  3. Arun says:

    Hi Amal,

    I was beginner and in AWS and I am able to connect. This works perfectly after trying many ways to connect.


  4. sree says:

    where is the code ???

  5. Parag says:

    Thanks for this Amal. Got me the information that I was looking for.

  6. tom says:

    is there any chance of getting the count from all regions in integers i.e count: 10

  7. tom says:

    How to get the total count of Instances and volumes and loadbalancers present in the aws using boto3.?

  8. Hi Amal ,
    Lambda function how to list down instance with region if they don’t have below tag with proper values?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: