Skip to content

Instantly share code, notes, and snippets.

@reecestart
Last active November 15, 2022 14:25
Show Gist options
  • Save reecestart/f32c433bb8ba45e4703830862e512416 to your computer and use it in GitHub Desktop.
Save reecestart/f32c433bb8ba45e4703830862e512416 to your computer and use it in GitHub Desktop.
Checks all Subnets in all Regions for those with less than 20 available IP addresses
import boto3
# Define the connection
client = boto3.client('ec2')
# Get all Regions
response = client.describe_regions()
# Create an Array for Region Names
RegionNames = []
# Fill the Region Names Array
Regions = response['Regions']
for i in Regions:
RegionNames.append(i['RegionName'])
# Get all Subnet IDs for each Region
print("Checking all regions for Subnets with Less than 20 Available IP Addresses")
for region in RegionNames:
client = boto3.client('ec2', region_name=region)
response = response = client.describe_subnets()
SubnetInfo = response['Subnets']
for i in SubnetInfo:
if (i['AvailableIpAddressCount'] < 20):
print(str(i['SubnetId']) + ' in ' + region + ' has ' + str(i['AvailableIpAddressCount']) + ' available IPs')
# Send final Comment
print("Checked all regions")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment