feat: added caching to aws region query

This commit is contained in:
KenF
2026-01-23 10:23:45 +08:00
parent c047662f78
commit a39c39a636
18 changed files with 91 additions and 79 deletions
+19 -6
View File
@@ -8,6 +8,17 @@ License: This program is released under the MIT License
# Imports
import boto3
from openpyxl import load_workbook
import concurrent.futures
import projectlib.aws
def getResources(region_name: str) -> list[list[str | int]]:
return_data = []
client = boto3.client('apigateway', region_name=region_name)
response = client.get_rest_apis()
for i in response['items']:
return_data.append([i["name"], i["endpointConfiguration"]["types"][0], region_name])
return return_data
# Main function
def main() -> None:
@@ -15,12 +26,14 @@ def main() -> None:
wb = load_workbook('aws-inventory.xlsx')
ws = wb.create_sheet("ApiGateway")
client = boto3.client('apigateway')
response = client.get_rest_apis()
ws.append(["RestAPIName","Scope"])
for i in response['items']:
ws.append([i["name"], i["endpointConfiguration"]["types"][0]])
ws.append(["RestAPIName","Scope","Region"])
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
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:
for row in region_rows:
ws.append(row)
wb.save('aws-inventory.xlsx')