feat: added caching to aws region query
This commit is contained in:
+2
-6
@@ -10,13 +10,9 @@ import boto3
|
||||
import concurrent.futures
|
||||
from openpyxl import load_workbook
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
import projectlib.aws
|
||||
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def getResources(region_name: str) -> list[list[str | int]]:
|
||||
return_data = []
|
||||
client = boto3.client('efs', region_name=region_name)
|
||||
@@ -33,7 +29,7 @@ def main() -> None:
|
||||
|
||||
ws.append(["FileSystemId", "Name", "PerformanceMode", "SizeMB", "AZ"])
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||
results = executor.map(getResources, getRegions())
|
||||
results = executor.map(getResources, projectlib.aws.getRegions())
|
||||
for region_rows in results:
|
||||
# append to worksheet only if resoruces are found in the region
|
||||
if region_rows:
|
||||
|
||||
Reference in New Issue
Block a user