Skip to content

Commit 889d0df

Browse files
author
Taniya Mathur
committed
Fix CloudFormation logs retrieval with pagination
Add pagination to get all stack events, not just recent 100
1 parent d7d0e5d commit 889d0df

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/codebuild_deployment.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,29 @@ def get_cloudformation_logs(stack_name):
325325
"""Get CloudFormation stack events for error analysis"""
326326
try:
327327
cf_client = boto3.client('cloudformation')
328-
response = cf_client.describe_stack_events(StackName=stack_name)
329-
events = response.get('StackEvents', [])
328+
all_events = []
329+
next_token = None
330+
331+
# Paginate through all events
332+
while True:
333+
if next_token:
334+
response = cf_client.describe_stack_events(
335+
StackName=stack_name,
336+
NextToken=next_token
337+
)
338+
else:
339+
response = cf_client.describe_stack_events(StackName=stack_name)
340+
341+
events = response.get('StackEvents', [])
342+
all_events.extend(events)
343+
344+
next_token = response.get('NextToken')
345+
if not next_token:
346+
break
330347

331348
# Filter for failed events
332349
failed_events = []
333-
for event in events:
350+
for event in all_events:
334351
status = event.get('ResourceStatus', '')
335352
if 'FAILED' in status or 'ROLLBACK' in status:
336353
failed_events.append({

0 commit comments

Comments
 (0)