from netaddr import * import boto3 ''' you will need the following pips: netaddr boto3 ''' AK='' SK='' inputs = [['us-west-2', 'vpc-7155ca14'],['eu-west-1','vpc-55a5a930']] for v1 in inputs: session = boto3.Session( aws_access_key_id=AK, aws_secret_access_key=SK, region_name=v1[0] ) ec2 = session.resource('ec2') vpc = ec2.Vpc(v1[1]) subnets = [] for subnet in vpc.subnets.all(): subnets.append(IPNetwork(subnet.cidr_block)) lastSubnet = sorted(subnets).pop() print (v1[0], 'next subnet:', lastSubnet.next())