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.