Use boto3 to rotate through all regions and count running instances in each.

IntermediateHands-onPython for DevOps
Answer
import boto3

regions = [r["RegionName"] for r in boto3.client("ec2", region_name="us-east-1").describe_regions()["Regions"]]
for region in regions:
    ec2 = boto3.client("ec2", region_name=region)
    n = sum(
        len(res["Instances"])
        for page in ec2.get_paginator("describe_instances").paginate(
            Filters=[{"Name": "instance-state-name", "Values": ["running"]}])
        for res in page["Reservations"]
    )
    if n:
        print(f"{region}: {n}")

Key trick → describe_regions returns only regions enabled for the account (opt-in regions excluded unless enabled), so you won't get auth errors from disabled regions.

All Real-World Interview questions Roadmap: Interview readiness

More on Python for DevOps