-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.github/workflows/util/clean/lambda_layer_cleanup/cleaner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import boto3 | ||
from datetime import datetime, timezone, timedelta | ||
import time | ||
|
||
client = boto3.client('apigateway') | ||
|
||
def delete_old_api_gateways(hours_old=3): | ||
now = datetime.now(timezone.utc) # Ensure `now` is timezone-aware | ||
cutoff_time = now - timedelta(hours=hours_old) | ||
|
||
print(f"Cutoff time: {cutoff_time}") | ||
|
||
apis = client.get_rest_apis() | ||
for api in apis.get('items', []): | ||
created_date = api.get('createdDate') # This is usually UTC already | ||
if created_date and isinstance(created_date, datetime): | ||
# Ensure `created_date` is timezone-aware | ||
created_date = created_date.astimezone(timezone.utc) | ||
|
||
if created_date < cutoff_time: | ||
api_id = api['id'] | ||
api_name = api.get('name', 'Unnamed API') | ||
print(f"Deleting API: {api_name} (ID: {api_id}), created at {created_date}") | ||
|
||
client.delete_rest_api(restApiId=api_id) | ||
print("Deleted successfully. Sleeping for 32 seconds...") | ||
time.sleep(32) | ||
else: | ||
print("Invalid or missing createdDate for API:", api) | ||
|
||
if __name__ == "__main__": | ||
delete_old_api_gateways() |
1 change: 1 addition & 0 deletions
1
.github/workflows/util/clean/lambda_layer_cleanup/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
boto3 |