Skip to content

Commit 57199b1

Browse files
author
Bob Strahan
committed
Remove Bedrock model access reminder from deployment email and add IDP log cleanup utilities
1 parent 38a9461 commit 57199b1

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed

delete_idp_logs.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python3
2+
import concurrent.futures
3+
import time
4+
from typing import List
5+
6+
import boto3
7+
from botocore.config import Config
8+
9+
10+
def delete_log_group(log_group_name: str) -> str:
11+
"""Delete a single log group"""
12+
try:
13+
config = Config(
14+
read_timeout=30, connect_timeout=10, retries={"max_attempts": 2}
15+
)
16+
client = boto3.client("logs", config=config)
17+
client.delete_log_group(logGroupName=log_group_name)
18+
return f"✓ Deleted: {log_group_name}"
19+
except Exception as e:
20+
return f"✗ Failed to delete {log_group_name}: {str(e)}"
21+
22+
23+
def get_idp_log_groups() -> List[str]:
24+
"""Get all log groups with 'LMA' in the name"""
25+
config = Config(read_timeout=30, connect_timeout=10, retries={"max_attempts": 2})
26+
client = boto3.client("logs", config=config)
27+
log_groups = []
28+
next_token = None
29+
page_count = 0
30+
31+
print("Scanning for log groups...")
32+
while True:
33+
try:
34+
page_count += 1
35+
print(f"Processing page {page_count}...")
36+
37+
kwargs = {"limit": 50}
38+
if next_token:
39+
kwargs["nextToken"] = next_token
40+
41+
response = client.describe_log_groups(**kwargs)
42+
43+
page_idp_count = 0
44+
for log_group in response["logGroups"]:
45+
if "LMA" in log_group["logGroupName"]:
46+
log_groups.append(log_group["logGroupName"])
47+
page_idp_count += 1
48+
49+
print(
50+
f"Page {page_count}: {page_idp_count} idp- groups, {len(log_groups)} total so far"
51+
)
52+
53+
if "nextToken" not in response:
54+
print("Reached end of log groups")
55+
break
56+
next_token = response["nextToken"]
57+
58+
except Exception as e:
59+
print(f"Error on page {page_count}: {e}")
60+
break
61+
62+
return log_groups
63+
64+
65+
def main():
66+
log_groups = get_idp_log_groups()
67+
68+
if not log_groups:
69+
print("No log groups found with 'idp-' in the name.")
70+
return
71+
72+
print(f"\nTotal found: {len(log_groups)} log groups")
73+
74+
confirm = input(f"Delete all {len(log_groups)} log groups? (y/N): ")
75+
if confirm.lower() != "y":
76+
print("Cancelled.")
77+
return
78+
79+
# Process in batches of 50
80+
batch_size = 50
81+
total_deleted = 0
82+
total_failed = 0
83+
84+
for i in range(0, len(log_groups), batch_size):
85+
batch = log_groups[i : i + batch_size]
86+
batch_num = (i // batch_size) + 1
87+
88+
print(
89+
f"Processing batch {batch_num}/{(len(log_groups) + batch_size - 1) // batch_size} ({len(batch)} log groups)..."
90+
)
91+
92+
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
93+
future_to_name = {
94+
executor.submit(delete_log_group, name): name for name in batch
95+
}
96+
97+
for future in concurrent.futures.as_completed(future_to_name, timeout=60):
98+
result = future.result()
99+
if result.startswith("✓"):
100+
total_deleted += 1
101+
else:
102+
total_failed += 1
103+
print(result)
104+
105+
print(
106+
f"Batch {batch_num} complete: {total_deleted} total deleted, {total_failed} total failed"
107+
)
108+
time.sleep(0.5)
109+
110+
print(f"\nFinal results: {total_deleted} deleted, {total_failed} failed")
111+
112+
113+
if __name__ == "__main__":
114+
main()

delete_idp_logs.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
echo "Getting all log groups with 'idp-' in name (case insensitive)..."
4+
aws logs describe-log-groups --output text --query 'logGroups[].logGroupName' | tr '\t' '\n' | grep -i 'test' > idp_log_groups.txt
5+
6+
total=$(wc -l < idp_log_groups.txt)
7+
echo "Found $total log groups to delete"
8+
9+
if [ $total -eq 0 ]; then
10+
echo "No log groups found"
11+
exit 0
12+
fi
13+
14+
echo "Deleting log groups in batches of 50..."
15+
split -l 50 idp_log_groups.txt batch_
16+
17+
batch_num=1
18+
for batch_file in batch_*; do
19+
echo "Processing batch $batch_num..."
20+
21+
# Delete each log group individually in parallel
22+
while IFS= read -r log_group; do
23+
{
24+
if aws logs delete-log-group --log-group-name "$log_group" 2>/dev/null; then
25+
echo "✓ Deleted: $log_group"
26+
else
27+
echo "✗ Failed: $log_group"
28+
fi
29+
} &
30+
31+
# Limit to 10 concurrent processes
32+
(($(jobs -r | wc -l) >= 10)) && wait
33+
done < "$batch_file"
34+
35+
# Wait for remaining jobs to complete
36+
wait
37+
38+
echo "Batch $batch_num complete"
39+
((batch_num++))
40+
sleep 1
41+
done
42+
43+
echo "Cleanup..."
44+
rm -f idp_log_groups.txt batch_*
45+
echo "Done!"

template.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4861,8 +4861,6 @@ Resources:
48614861
<p>When the CloudFormation stack is COMPLETE, use the link below to log in and set your permanent password.
48624862
<p> https://${CloudFrontDistribution.DomainName}/
48634863
<p>
4864-
<p>If you have not previously done so, you must request access to the following Amazon Bedrock models: Amazon: Titan Text Embeddings V2, Amazon: Nova models, Anthropic: Claude 3, 3.x, and 4.x models. (https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html)
4865-
<p>
48664864
<p>Thanks,</p>
48674865
<p>AWS GenAIIDP Team</p>
48684866
<p>

0 commit comments

Comments
 (0)