in source/Lambda/innovation_delete_default_vpcs.py [0:0]
def del_sub(ec2, vpc_id):
""" Delete the subnets """
try:
response = ec2.describe_subnets(
Filters=[
{
'Name': 'vpc-id',
'Values': [
vpc_id
],
},
]
)
except Exception as e:
message = {'MESSAGE': 'Exception occured while fetching Subnets in default VPC', 'FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
logger.exception(message)
raise
subnets = response['Subnets']
try:
for subnet in subnets:
if 'DefaultForAz' in subnet.keys() and subnet['DefaultForAz'] is True:
subnet_id = subnet['SubnetId']
ec2.delete_subnet(SubnetId = subnet_id)
except Exception as e:
message = {'MESSAGE': 'Exception occured while deleting Subnets in default VPC', 'FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
logger.exception(message)
raise