Skip to content

Commit 0493029

Browse files
committed
Merge branch 'feature/pipeline-error-logging' into 'develop'
Feature/pipeline error logging See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!420
2 parents def0d03 + 6704f56 commit 0493029

15 files changed

+590
-117
lines changed

.gitlab-ci.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ developer_tests:
4343
- uv venv .venv
4444
- source .venv/bin/activate
4545
# Install Node.js and npm for basedpyright
46-
- curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
46+
- curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
4747
- apt-get install -y nodejs
48+
- npm install -g npm@11
4849
- npm install -g basedpyright
4950
- uv pip install ruff
5051
# Install dependencies needed by publish.py for test imports
5152
- uv pip install typer rich boto3
5253
# Install test dependencies
53-
- cd lib/idp_common_pkg && uv pip install -e ".[test]" && cd ../..
54+
- cd lib/idp_common_pkg && uv pip install -e ".[test,evaluation]" && cd ../..
5455

5556
script:
5657
- make lint-cicd
@@ -163,15 +164,20 @@ integration_tests:
163164
164165
# Save full logs to artifact
165166
echo "$FULL_LOGS" > codebuild_logs.txt
166-
echo "📁 Full deployment logs saved to: codebuild_logs.txt"
167-
167+
echo -e "\033[1;36m📁 Full deployment logs saved to: \033[1;33mcodebuild_logs.txt\033[0m"
168+
echo -e "\033[1;34m🔗 View logs: ${CI_JOB_URL}/artifacts/external_file/codebuild_logs.txt\033[0m"
168169
# Extract and show deployment summary (AI or manual)
169170
echo ""
170-
SUMMARY=$(echo "$FULL_LOGS" | grep -A 100 "🤖 Generating deployment summary with Bedrock..." | head -100)
171+
SUMMARY=$(echo "$FULL_LOGS" | sed -n '/🤖 Generating deployment summary with Bedrock.../,$p' | sed 's/^\t*//' | grep -v '\[Container\]' | grep -v 'Phase complete:' | grep -v 'Phase context status code:' | grep -v 'Entering phase' || true)
171172
172173
if [ -n "$SUMMARY" ]; then
173-
echo "🤖 Deployment Analysis:"
174-
echo "$SUMMARY"
174+
echo "┌─────────────────────────────────────────────────────────────────────────┐"
175+
echo "│ DEPLOYMENT SUMMARY │"
176+
echo "├─────────────────────────────────────────────────────────────────────────┤"
177+
echo "$SUMMARY" | while IFS= read -r line; do
178+
printf "│ %-71s │\n" "$line"
179+
done
180+
echo "└─────────────────────────────────────────────────────────────────────────┘"
175181
else
176182
echo "⚠️ No deployment summary found - check codebuild_logs.txt for details"
177183
fi

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ You need to have the following packages installed on your computer:
114114
4. python 3.11 or later
115115
5. A local Docker daemon
116116
6. Python packages for publish.py: `pip install boto3 rich typer PyYAML botocore setuptools ruff`
117-
7. **Node.js 18+** and **npm** (required for UI validation in publish script)
117+
7. **Node.js 22.12+** and **npm** (required for UI validation in publish script)
118118

119119
For guidance on setting up a development environment, see:
120120

docs/setup-development-env-WSL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cd accelerated-intelligent-document-processing-on-aws
4444
```
4545
This script automatically installs:
4646
- Git, Python 3, pip, and build tools
47-
- Node.js 18
47+
- Node.js 22
4848
- AWS CLI v2
4949
- AWS SAM CLI
5050
- Python dependencies
@@ -77,8 +77,8 @@ Enter your AWS credentials when prompted. Refer to: https://docs.aws.amazon.com/
7777
python3 --version (Example: Python 3.12.3)
7878
aws --version (Example: aws-cli/2.28.26)
7979
sam --version (Example: SAM CLI, version 1.143.0)
80-
node --version (Example: v18.20.8)
81-
npm --version (Example: 10.8.2)
80+
node --version (Example: v22.12.0)
81+
npm --version (Example: 11.0.0)
8282
```
8383
### 4.2 Test Build Process
8484
```

docs/setup-development-env-macos.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ sam --version
142142
```
143143

144144

145-
## 7) Node.js via nvm (Node 18 LTS)
145+
## 7) Node.js via nvm (Node 22 LTS)
146146

147147
Use nvm to manage Node versions. This mirrors your Linux section but uses zsh-friendly profile updates.
148148

@@ -156,9 +156,9 @@ fi
156156
export NVM_DIR="$HOME/.nvm"
157157
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
158158

159-
# Install Node 18 LTS
160-
nvm install 18
161-
nvm alias default 18
159+
# Install Node 22 LTS
160+
nvm install 22
161+
nvm alias default 22
162162

163163
# Test
164164
node -v

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"typecheck:stats": "basedpyright --stats"
1818
},
1919
"engines": {
20-
"node": ">=18.0.0",
21-
"npm": ">=9.0.0"
20+
"node": ">=22.12.0",
21+
"npm": ">=11.0.0"
2222
}
2323
}

publish.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ check_nodejs_dependencies() {
108108
node_version=$(node --version 2>/dev/null | sed 's/v//')
109109
node_major=$(echo "$node_version" | cut -d'.' -f1)
110110

111-
if [[ "$node_major" -lt 18 ]]; then
112-
print_error "Node.js $node_version found, but 18+ is required for UI validation"
111+
if [[ "$node_major" -lt 22 ]]; then
112+
print_error "Node.js $node_version found, but 22+ is required for UI validation"
113113
print_info "Please upgrade Node.js to version 18 or later"
114114
exit 1
115115
else

scripts/codebuild_deployment.py

Lines changed: 99 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5858
def 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

105104
def 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+
270328
def 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-
442458
def 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

scripts/dev_setup_al2023.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-lin
4848
unzip aws-sam-cli-linux-x86_64.zip -d ./sam-cli
4949
sudo ./sam-cli/install --update
5050

51-
# node 18
51+
# node 22
5252
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash # nosemgrep: bash.curl.security.curl-pipe-bash.curl-pipe-bash - Official NVM installation script for development environment only
5353
source ~/.bashrc
5454
nvm install 18

scripts/dev_setup_ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ wget -q https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-
4343
unzip -q aws-sam-cli-linux-x86_64.zip -d ./sam-cli
4444
sudo ./sam-cli/install --update
4545

46-
# node 20
46+
# node 22
4747
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
4848
export NVM_DIR="$HOME/.nvm"
4949
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

scripts/sdlc/cfn/codepipeline-s3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Resources:
198198
python: 3.12
199199
commands:
200200
- n 22 && node --version || { echo "Node setup failed"; exit 1; }
201-
- npm install -g aws-cdk || { echo "CDK installation failed"; exit 1; }
201+
- npm install -g npm@11 || { echo "npm upgrade failed"; exit 1; }
202202
- export IDP_ADMIN_EMAIL=$(aws s3api head-object --bucket genaiic-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 "")
203203
- cd idp_cli && pip install -e . && cd .. || { echo "IDP CLI installation failed"; exit 1; }
204204
- pip install rich || echo "Rich installation failed, using fallback formatting"

0 commit comments

Comments
 (0)