def get_subnet_by_region()

in code/ct_flowlog_activator.py [0:0]


def get_subnet_by_region(target_session, accountId, region):
    '''
    Find all subnets in the region based on the account ID
    '''
    try:
        ec2_client = target_session.client('ec2', region_name=region)
        response = ec2_client.describe_subnets(
            Filters=[
                {
                    'Name': 'owner-id',
                    'Values': [accountId]
                }
            ],
            MaxResults=10
        )
        subnet_list = response['Subnets']

        while 'NextToken' in response:
            response = ec2_client.describe_subnets(
                NextToken=response['NextToken']
            )
            subnet_list += response['Subnets']

        if not subnet_list:
            LOGGER.info(f'No Subnets found for account {accountId}')
        return subnet_list

    except Exception as e:
        LOGGER.error("Could not describe Subnet : {}".format(e), exc_info=True)
        return []