Skip to content

Instantly share code, notes, and snippets.

@hingstarne
Last active November 18, 2019 09:52
Show Gist options
  • Save hingstarne/40b3250c434964974bfb6b196d2cecbf to your computer and use it in GitHub Desktop.
Save hingstarne/40b3250c434964974bfb6b196d2cecbf to your computer and use it in GitHub Desktop.
#/usr/bin/env python3
import boto3
from termcolor import colored
subnetsIDs={}
ec2 = boto3.resource('ec2')
client = boto3.client('ec2')
response=client.describe_subnets()
for i in response['Subnets']:
subnetsIDs[i['SubnetId']]=0
response=client.describe_nat_gateways()
for i in response['NatGateways']:
subnetsIDs[i['SubnetId']]=1
client = boto3.client('rds')
response = client.describe_db_instances()
for i in response['DBInstances']:
for x in i['DBSubnetGroup']['Subnets']:
subnetsIDs[x['SubnetIdentifier']]=1
client = boto3.client('autoscaling')
response=client.describe_auto_scaling_groups()
for i in response['AutoScalingGroups']:
subnetsIDs[i['VPCZoneIdentifier']]=1
for i in ec2.instances.all():
subnetsIDs[i.subnet_id]=1
for each in subnetsIDs.keys():
if subnetsIDs[each] == 0:
print(each)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment