in code/ct_flowlog_activator.py [0:0]
def get_vpc_by_region(target_session, accountId, region):
'''
Find all VPC in the region based on the account ID
'''
try:
LOGGER.info(f'Getting list of accounts for {accountId} in region {region}')
ec2_client = target_session.client('ec2', region_name=region)
response = ec2_client.describe_vpcs(
Filters=[
{
'Name': 'owner-id',
'Values': [accountId]
}
],
MaxResults=10
)
vpc_list = response['Vpcs']
LOGGER.debug(f'ec2_client.describe_vpcs returned: {json.dumps(vpc_list)}')
while 'NextToken' in response:
response = ec2_client.describe_vpcs(
NextToken=response['NextToken']
)
vpc_list += response['Vpcs']
if not vpc_list:
LOGGER.info(f'No VPCs found for account {accountId}')
return vpc_list
except Exception as e:
LOGGER.error("Could not describe VPC : {}".format(e), exc_info=True)
return []