Skip to content

Commit 5660eb6

Browse files
author
Taniya Mathur
committed
Add Rich-formatted Bedrock deployment summary with GitLab integration
- Update Bedrock prompt to generate structured table format with root cause analysis - Add Rich library for colored panel formatting in CodeBuild logs - Save full deployment logs to codebuild_logs.txt artifact - Show only AI/manual summary in GitLab runner logs for cleaner output - Include detailed failure analysis for all patterns with specific error messages
1 parent 93e619e commit 5660eb6

File tree

3 files changed

+71
-15
lines changed

3 files changed

+71
-15
lines changed

.gitlab-ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,30 @@ integration_tests:
155155
LOG_STREAM_NAME="${BUILD_ID#*:}"
156156
echo "Log Stream: $LOG_STREAM_NAME"
157157
echo ""
158-
echo "=== CODEBUILD LOGS ==="
158+
echo "=== DEPLOYMENT SUMMARY ==="
159159
# Wait for CloudWatch Logs to flush all events
160160
echo "Waiting 30 seconds for logs to flush..."
161161
sleep 30
162-
aws logs get-log-events --log-group-name "/aws/codebuild/app-sdlc" --log-stream-name "$LOG_STREAM_NAME" --start-from-head --query 'events[].message' --output text 2>/dev/null || echo "Could not retrieve CodeBuild logs"
162+
FULL_LOGS=$(aws logs get-log-events --log-group-name "/aws/codebuild/app-sdlc" --log-stream-name "$LOG_STREAM_NAME" --start-from-head --query 'events[].message' --output text 2>/dev/null || echo "Could not retrieve CodeBuild logs")
163+
164+
# Save full logs to artifact
165+
echo "$FULL_LOGS" > codebuild_logs.txt
166+
echo "📁 Full deployment logs saved to: codebuild_logs.txt"
167+
168+
# Extract and show AI summary or manual summary
169+
echo ""
170+
AI_SUMMARY=$(echo "$FULL_LOGS" | grep -A 50 "AI Deployment Analysis" | head -50)
171+
MANUAL_SUMMARY=$(echo "$FULL_LOGS" | grep -A 20 "DEPLOYMENT SUMMARY REPORT" | head -20)
172+
173+
if [ -n "$AI_SUMMARY" ]; then
174+
echo "🤖 AI-Powered Deployment Analysis:"
175+
echo "$AI_SUMMARY"
176+
elif [ -n "$MANUAL_SUMMARY" ]; then
177+
echo "📋 Deployment Summary:"
178+
echo "$MANUAL_SUMMARY"
179+
else
180+
echo "⚠️ No deployment summary available"
181+
fi
163182
else
164183
echo "Could not find CodeBuild execution"
165184
fi
@@ -171,4 +190,5 @@ integration_tests:
171190
when: always
172191
paths:
173192
- pipeline_execution_id.txt
193+
- codebuild_logs.txt
174194
expire_in: 1 week

scripts/codebuild_deployment.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
291291

292292
# Create prompt for Bedrock with actual logs
293293
prompt = dedent(f"""
294-
You are an AWS deployment analyst. Analyze the following deployment logs and create a comprehensive summary.
294+
You are an AWS deployment analyst. Analyze the following deployment logs and create a concise summary in table format.
295295
296296
Deployment Information:
297297
- Timestamp: {datetime.now().isoformat()}
@@ -305,14 +305,36 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
305305
Pattern Results Summary:
306306
{json.dumps(deployment_results, indent=2)}
307307
308-
Please provide:
309-
1. Executive Summary (2-3 sentences)
310-
2. Deployment Status Overview
311-
3. Pattern-by-Pattern Analysis
312-
4. Failure Analysis (extract specific errors from logs)
313-
5. Recommendations based on log analysis
314-
315-
Focus on extracting failure reasons from the actual logs and provide actionable insights.
308+
Create a summary with this EXACT format:
309+
310+
┌─────────────────────────────────────────────────────────────────────────────┐
311+
│ DEPLOYMENT RESULTS │
312+
├─────────────────────────────────────────────────────────────────────────────┤
313+
│ Pattern │ Status │ Duration │ Key Metrics │
314+
├─────────────────────────────────────────────────────────────────────────────┤
315+
│ Pattern 1 - BDA │ SUCCESS │ 15m 30s │ 28 functions validated │
316+
│ Pattern 2 - OCR │ SUCCESS │ 12m 45s │ All tests passed │
317+
├─────────────────────────────────────────────────────────────────────────────┤
318+
│ ROOT CAUSE ANALYSIS │
319+
├─────────────────────────────────────────────────────────────────────────────┤
320+
│ • CloudWatch log cleanup failed due to concatenated log group names │
321+
│ • AWS CLI text output parsing caused parameter validation errors │
322+
│ • Provide specific error messages, resource names, and failure points │
323+
├─────────────────────────────────────────────────────────────────────────────┤
324+
│ RECOMMENDATIONS │
325+
├─────────────────────────────────────────────────────────────────────────────┤
326+
│ • Fix CloudWatch log cleanup to use JSON output instead of text │
327+
│ • Add proper error handling for resource cleanup operations │
328+
└─────────────────────────────────────────────────────────────────────────────┘
329+
330+
Requirements:
331+
- Use EXACT table format above
332+
- For failures: provide detailed root cause analysis for ALL failed patterns
333+
- Include specific error messages, resource names, and exact failure points from logs
334+
- Include sufficient technical details to understand WHY each pattern failed
335+
- Maximum 2-3 bullet points for recommendations
336+
- Keep each line under 75 characters
337+
- Extract actual error messages and resource identifiers from logs
316338
""")
317339

318340
# Call Bedrock API
@@ -334,10 +356,23 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
334356
response_body = json.loads(response['body'].read())
335357
summary = response_body['content'][0]['text']
336358

337-
print("📊 Deployment Summary Generated:")
338-
print("=" * 80)
339-
print(summary)
340-
print("=" * 80)
359+
try:
360+
from rich.console import Console
361+
from rich.panel import Panel
362+
363+
console = Console()
364+
console.print(Panel(
365+
summary,
366+
title="🤖 AI Deployment Analysis",
367+
border_style="green",
368+
padding=(1, 2)
369+
))
370+
except ImportError:
371+
# Fallback to plain text if Rich not available
372+
print("📊 Deployment Summary Generated:")
373+
print("=" * 80)
374+
print(summary)
375+
print("=" * 80)
341376

342377
return summary
343378

scripts/sdlc/cfn/codepipeline-s3.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Resources:
161161
- npm install -g aws-cdk || { echo "CDK installation failed"; exit 1; }
162162
- export IDP_ADMIN_EMAIL=$(aws s3api head-object --bucket idp-sdlc-sourcecode-${AWS_ACCOUNT_ID:-020432867916}-${AWS_DEFAULT_REGION:-us-east-1} --key deploy/code.zip --query 'Metadata."gitlab-user-email"' --output text 2>/dev/null || echo "")
163163
- cd idp_cli && pip install -e . && cd .. || { echo "IDP CLI installation failed"; exit 1; }
164+
- pip install rich || echo "Rich installation failed, using fallback formatting"
164165
build:
165166
commands:
166167
- python3 scripts/codebuild_deployment.py

0 commit comments

Comments
 (0)