@@ -51,16 +51,15 @@ def run_command(cmd, check=True):
5151 print (result .stderr , file = sys .stderr )
5252 if check and result .returncode != 0 :
5353 print (f"Command failed with exit code { result .returncode } " )
54- sys . exit ( 1 )
54+ raise Exception ( f"Command failed: { cmd } " )
5555 return result
5656
5757
5858def get_env_var (name , default = None ):
5959 """Get environment variable with optional default"""
6060 value = os .environ .get (name , default )
6161 if value is None :
62- print (f"Error: Environment variable { name } is required" )
63- sys .exit (1 )
62+ raise Exception (f"Environment variable { name } is required" )
6463 return value
6564
6665
@@ -99,7 +98,7 @@ def publish_templates():
9998 return template_url
10099 else :
101100 print ("❌ Failed to extract template URL from publish output" )
102- sys . exit ( 1 )
101+ raise Exception ( "Failed to extract template URL from publish output" )
103102
104103
105104def deploy_test_and_cleanup_pattern (stack_prefix , pattern_config , admin_email , template_url ):
@@ -267,6 +266,65 @@ def get_codebuild_logs():
267266 return f"Failed to retrieve CodeBuild logs: { str (e )} "
268267
269268
269+ def generate_publish_failure_summary (publish_error ):
270+ """Generate summary for publish/build failures"""
271+ try :
272+ bedrock = boto3 .client ('bedrock-runtime' )
273+
274+ prompt = dedent (f"""
275+ You are a build system analyst. Analyze this publish/build failure and provide specific technical guidance.
276+
277+ Publish Error: { publish_error }
278+
279+ Build Logs:
280+ { get_codebuild_logs ()}
281+
282+ ANALYZE THE LOGS FOR: npm ci errors, package-lock.json sync issues, missing @esbuild packages, UI build failures
283+
284+ Create a summary focused on BUILD/PUBLISH issues with bullet points:
285+
286+ 🔧 BUILD FAILURE ANALYSIS
287+
288+ 📋 Component Status:
289+ • UI Build: FAILED - npm dependency issues
290+ • Lambda Build: SUCCESS - All patterns built correctly
291+ • Template Publish: FAILED - S3 access denied
292+
293+ 🔍 Technical Root Cause:
294+ • Extract exact npm/pip error messages from logs
295+ • Identify specific missing packages or version conflicts
296+ • Focus on build-time errors, not deployment errors
297+ • Check AWS credentials and S3 bucket permissions
298+
299+ 💡 Fix Commands:
300+ • Run: cd src/ui && rm package-lock.json && npm install
301+ • Check AWS profile: aws configure list --profile <name>
302+ • Verify S3 access: aws s3 ls s3://bucket-name --profile <name>
303+ • Update package-lock.json and commit changes
304+
305+ Keep each bullet point under 75 characters. Use sub-bullets for details.
306+
307+ IMPORTANT: Respond ONLY with the bullet format above. Do not include any text before or after.
308+ """ )
309+
310+ response = bedrock .invoke_model (
311+ modelId = 'anthropic.claude-3-5-sonnet-20240620-v1:0' ,
312+ body = json .dumps ({
313+ "anthropic_version" : "bedrock-2023-05-31" ,
314+ "max_tokens" : 2000 ,
315+ "messages" : [{"role" : "user" , "content" : prompt }]
316+ })
317+ )
318+
319+ response_body = json .loads (response ['body' ].read ())
320+ summary = response_body ['content' ][0 ]['text' ]
321+
322+ print (summary )
323+
324+ except Exception as e :
325+ print (f"⚠️ Failed to generate build failure summary: { e } " )
326+
327+
270328def generate_deployment_summary (deployment_results , stack_prefix , template_url ):
271329 """
272330 Generate deployment summary using Bedrock API
@@ -306,38 +364,38 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
306364 Pattern Results Summary:
307365 { json .dumps (deployment_results , indent = 2 )}
308366
309- Create a summary with this EXACT format:
310-
311- ┌─────────────────────────────────────────────────────────────────────────────┐
312- │ DEPLOYMENT RESULTS │
313- ├─────────────────────────────────────────────────────────────────────────────┤
314- │ Pattern │ Status │ Duration │ Key Metrics │
315- ├─────────────────────────────────────────────────────────────────────────────┤
316- │ Pattern 1 - BDA │ SUCCESS │ 15m 30s │ 28 functions validated │
317- │ Pattern 2 - OCR │ SUCCESS │ 12m 45s │ All tests passed │
318- ├─────────────────────────────────────────────────────────────────────────────┤
319- │ ROOT CAUSE ANALYSIS │
320- ├─────────────────────────────────────────────────────────────────────────────┤
321- │ • CloudWatch log cleanup failed due to concatenated log group names │
322- │ • AWS CLI text output parsing caused parameter validation errors │
323- │ • Provide specific error messages, resource names, and failure points │
324- ├─────────────────────────────────────────────────────────────────────────────┤
325- │ RECOMMENDATIONS │
326- ├─────────────────────────────────────────────────────────────────────────────┤
327- │ • Fix CloudWatch log cleanup to use JSON output instead of text │
328- │ • Add proper error handling for resource cleanup operations │
329- └─────────────────────────────────────────────────────────────────────────────┘
367+ Create a summary with clean bullet format:
368+
369+ 🚀 DEPLOYMENT RESULTS
370+
371+ 📋 Pattern Status:
372+ • Pattern 1 - BDA: SUCCESS - Stack deployed successfully (120s)
373+ • Pattern 2 - OCR: FAILED - CloudFormation CREATE_FAILED (89s)
374+ • Pattern 3 - UDOP: SKIPPED - Not selected for deployment
375+
376+ 🔍 Root Cause Analysis:
377+ • Analyze actual deployment results from Pattern Results Summary
378+ • Extract specific CloudFormation error messages and resource names
379+ • Focus on CREATE_FAILED, UPDATE_FAILED, ROLLBACK events
380+ • Check for smoke test failures and their underlying causes
381+ • Report Lambda function errors, API Gateway issues, IAM permissions
382+
383+ 💡 Recommendations:
384+ • Use actual pattern names and statuses from deployment_results
385+ • Include specific CloudFormation stack names and error details
386+ • Provide smoke test error details and remediation steps
387+
388+ Keep each bullet point under 75 characters. Use clean text format.
389+
390+ IMPORTANT: Respond ONLY with clean bullet format above. No tables or boxes.
330391
331392 Requirements:
332- - Use EXACT table format above
333- - For failures: provide detailed root cause analysis for ALL failed components (publish, deployments, etc.)
334- - Analyze publish/build logs to determine root cause of template publishing errors
335- - Include specific error messages, resource names, and exact failure points from logs
336- - Include sufficient technical details to understand WHY each component failed
337- - Maximum 2-3 bullet points for recommendations
338- - Keep each line under 75 characters
339- - Extract actual error messages and resource identifiers from logs
340- - For publish failures: check S3 permissions, npm/pip errors, CDK issues, template syntax
393+ - Analyze ALL error messages in logs for specific technical details
394+ - Include exact CloudFormation/Lambda error messages and specific commands to fix
395+ - Extract specific error patterns like "CREATE_FAILED", "UPDATE_FAILED", "ROLLBACK"
396+ - Provide detailed technical root cause analysis with specific resource names
397+ - Include actionable recommendations with exact terminal commands
398+
341399 """ )
342400
343401 # Call Bedrock API
@@ -359,23 +417,7 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
359417 response_body = json .loads (response ['body' ].read ())
360418 summary = response_body ['content' ][0 ]['text' ]
361419
362- try :
363- from rich .console import Console
364- from rich .panel import Panel
365-
366- console = Console ()
367- console .print (Panel (
368- summary ,
369- title = "🤖 AI Deployment Analysis" ,
370- border_style = "green" ,
371- padding = (1 , 2 )
372- ))
373- except ImportError :
374- # Fallback to plain text if Rich not available
375- print ("📊 Deployment Summary Generated:" )
376- print ("=" * 80 )
377- print (summary )
378- print ("=" * 80 )
420+ print (summary )
379421
380422 return summary
381423
@@ -413,32 +455,6 @@ def generate_deployment_summary(deployment_results, stack_prefix, template_url):
413455
414456 return manual_summary
415457
416-
417- def delete_versioned_bucket (bucket_name ):
418- """Delete all versions and delete markers from a versioned S3 bucket, then delete the bucket."""
419- import boto3
420- try :
421- s3 = boto3 .client ('s3' )
422- paginator = s3 .get_paginator ('list_object_versions' )
423-
424- for page in paginator .paginate (Bucket = bucket_name ):
425- # Delete object versions
426- if 'Versions' in page :
427- for version in page ['Versions' ]:
428- s3 .delete_object (Bucket = bucket_name , Key = version ['Key' ], VersionId = version ['VersionId' ])
429-
430- # Delete delete markers
431- if 'DeleteMarkers' in page :
432- for marker in page ['DeleteMarkers' ]:
433- s3 .delete_object (Bucket = bucket_name , Key = marker ['Key' ], VersionId = marker ['VersionId' ])
434-
435- # Delete the bucket
436- s3 .delete_bucket (Bucket = bucket_name )
437- return True
438- except Exception :
439- return False
440-
441-
442458def cleanup_stack (stack_name , pattern_name ):
443459 print (f"[{ pattern_name } ] Cleaning up: { stack_name } " )
444460 try :
@@ -513,10 +529,12 @@ def main():
513529 try :
514530 template_url = publish_templates ()
515531 publish_success = True
532+ publish_error = None
516533 except Exception as e :
517534 print (f"❌ Publish failed: { e } " )
518535 template_url = "N/A - Publish failed"
519536 publish_success = False
537+ publish_error = str (e )
520538
521539 all_success = publish_success
522540 deployment_results = []
@@ -571,7 +589,10 @@ def main():
571589 # Step 3: Generate deployment summary using Bedrock (ALWAYS run for analysis)
572590 print ("\n 🤖 Generating deployment summary with Bedrock..." )
573591 try :
574- generate_deployment_summary (deployment_results , stack_prefix , template_url )
592+ if not publish_success :
593+ generate_publish_failure_summary (publish_error )
594+ else :
595+ generate_deployment_summary (deployment_results , stack_prefix , template_url )
575596 except Exception as e :
576597 print (f"⚠️ Failed to generate deployment summary: { e } " )
577598
0 commit comments