Created
April 7, 2019 08:30
-
-
Save RadoRado/ecb2078346bb3b55297d88b8154fa1f6 to your computer and use it in GitHub Desktop.
Quick and dirty script to find out what EC2 instances are existing in which regions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from subprocess import check_output | |
| from shlex import split | |
| import json | |
| REGIONS = ( | |
| 'us-east-2', | |
| 'us-east-1', | |
| 'us-west-1', | |
| 'us-west-2', | |
| 'ap-south-1', | |
| 'ap-northeast-3', | |
| 'ap-northeast-2', | |
| 'ap-southeast-1', | |
| 'ap-southeast-2', | |
| 'ap-northeast-1', | |
| 'ca-central-1', | |
| 'cn-north-1', | |
| 'cn-northwest-1', | |
| 'eu-central-1', | |
| 'eu-west-1', | |
| 'eu-west-2', | |
| 'eu-west-3', | |
| 'eu-north-1', | |
| 'sa-east-1', | |
| 'us-gov-east-1', | |
| 'us-gov-west-1' | |
| ) | |
| COMMAND = 'aws ec2 describe-instances --region={region}' | |
| for region in REGIONS: | |
| command = COMMAND.format(region=region) | |
| print(region) | |
| try: | |
| output = check_output(split(command)).decode('utf-8') | |
| response = json.loads(output) | |
| print(len(response['Reservations'])) | |
| except Exception as exc: | |
| print(f'Calling failed with exception: {exc}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment