Skip to content

Conversation

asifma
Copy link

@asifma asifma commented Oct 10, 2025

Description

This PR adds a new sample demonstrating AI-powered Lambda error analysis using Amazon Bedrock and Strands Agents SDK. The system automatically investigates Lambda failures and provides root cause analysis with actionable fix recommendations.

What's New

AI-Powered Error Analyzer

  • Strands Agent with Claude Sonnet 4 (with interleaved thinking) and Claude 3.7 Sonnet
  • Event-driven architecture using EventBridge for automatic error detection
  • Multi-tool agent with 3 specialized capabilities:
    • fetch_source_code - Retrieves Lambda source from S3/deployment package
    • fetch_cloudwatch_logs - Gets execution logs filtered by request ID
    • search_knowledge_base - Queries Bedrock Knowledge Base for error patterns
  • Confidence scoring system (0.0-1.0) based on evidence quality

Complete CDK Infrastructure

  • 2 Lambda functions (sample business function + error analyzer)
  • Amazon Bedrock Knowledge Base with S3 data source
  • DynamoDB table for analysis history
  • EventBridge rules for event orchestration
  • IAM roles with least-privilege permissions
  • CDK Nag compliance checks

Key Features

  • 🤖 Automated error investigation with AI reasoning between tool calls
  • 📊 Evidence-based confidence scoring
  • 🔍 Multi-source analysis (source code, logs, documentation)
  • 📚 Knowledge Base with error patterns and best practices
  • 🎯 Actionable recommendations with specific code fixes
  • 📓 Interactive Jupyter notebook for deployment and testing

Project Structure

lambda-error-analysis-agent/
├── cdk/
│   ├── lambda/
│   │   ├── sample-business-function/      # Business logic with @error_capture
│   │   │   ├── lambda_function.py         # User registration processor
│   │   │   ├── decorator.py               # @error_capture decorator
│   │   │   └── test-events.json           # 9 test scenarios
│   │   └── error-analyzer-agent/          # AI Error Analyzer
│   │       ├── lambda_function.py         # Main handler
│   │       ├── agent.py                   # Strands Agent with 3 tools
│   │       └── requirements.txt
│   ├── layers/strands-layer/              # Lambda Layer with dependencies
│   └── stacks/lambda-error-analysis-stack.ts
├── knowledge_base/                        # Documentation for AI agent
│   ├── common-errors.md
│   ├── lambda-error-patterns.md
│   ├── user-data-validation-patterns.md
│   └── troubleshooting-guide.md
├── images/                              # Architecture diagrams
│   ├── generate_diagram.py               # Reproducible diagram generation
│   └── lambda-error-analysis-architecture.png
├── deploy-agent.ipynb                     # Interactive deployment notebook
├── cdk-app.ts                            # CDK entry point
├── package.json                          # CDK dependencies
└── README.md                             # Readme - comprehensive documentation

Testing

  • Successfully deployed to AWS account
  • Verified Lambda functions execute correctly
  • Tested 9 error scenarios with AI analysis
  • Validated Knowledge Base ingestion and search
  • Confirmed EventBridge triggers analyzer correctly
  • Verified DynamoDB stores analysis results with confidence scores

Documentation

  • README follows template structure with Sample Details table
  • Interactive Jupyter notebook for guided deployment
  • Architecture diagrams in images/ directory
  • Knowledge Base documentation with error patterns

Checklist

  • Follows project structure guidelines from .github/templates/02-samples/
  • README follows template format (Sample Details table, all required sections)
  • Local testing completed successfully
  • Documentation is complete and clear
  • CDK Nag security checks pass
  • No hardcoded credentials or sensitive data
  • Build artifacts excluded from commit
  • Added to 02-samples/README.md table as entry 16

asiif added 2 commits October 10, 2025 18:12
- AI-powered Lambda error diagnostics with root cause analysis
- Event-driven architecture with EventBridge integration
- Multi-tool Strands agent (source code, CloudWatch logs, Knowledge Base)
- Confidence scoring system for analysis quality
- Complete CDK infrastructure with Bedrock Knowledge Base
- Interactive Jupyter notebook for deployment and testing
- 9 comprehensive test scenarios covering common validation errors
- Features Claude Sonnet 4 with interleaved thinking
- Add required Sample Details table with all metadata
- Simplify and reorganize sections per template structure
- Rename diagrams/ to images/ for consistency
- Update all image references in README and notebook
- Add Cleanup section with destroy instructions
- Add Disclaimer section for production use
- Update model IDs to correct versions (Claude 3.7 and Sonnet 4)
- Convert Project Structure and Troubleshooting to table format
- Remove verbose sections (detailed content in Jupyter notebook)
- Follow template: concise, actionable, well-structured
@asifma asifma changed the title Add AI-Powered Lambda Error Analysis Agent sampleSample/lambda error analysis agent Add AI-Powered Lambda Error Analysis Agent sample Oct 10, 2025
asiif added 3 commits October 13, 2025 11:11
- Use consistent format: Claude Sonnet 3.7 and Claude Sonnet 4
- Update all references throughout README
- Model name (Sonnet) followed by version number
- Implement pagination to handle large log streams (up to 100K events)
- Stop early when START marker found for efficiency
- Handle gaps in log streams gracefully
- Add MAX_CLOUDWATCH_LOG_EVENTS constant (10K per page)
- Improve logging to show pages fetched
- Ensures complete execution logs are retrieved even if far back in stream
Copy link

Latest scan for commit: c94e2db | Updated: 2025-10-15 05:27:45 UTC

✅ Security Scan Report (PR Files Only)

Scanned Files

  • 02-samples/16-lambda-error-analysis-agent/.gitignore
  • 02-samples/16-lambda-error-analysis-agent/README.md
  • 02-samples/16-lambda-error-analysis-agent/cdk-app.ts
  • 02-samples/16-lambda-error-analysis-agent/cdk.json
  • 02-samples/16-lambda-error-analysis-agent/cdk/constant.ts
  • 02-samples/16-lambda-error-analysis-agent/cdk/lambda/error-analyzer-agent/agent.py
  • 02-samples/16-lambda-error-analysis-agent/cdk/lambda/error-analyzer-agent/lambda_function.py
  • 02-samples/16-lambda-error-analysis-agent/cdk/lambda/sample-business-function/README.md
  • 02-samples/16-lambda-error-analysis-agent/cdk/lambda/sample-business-function/decorator.py
  • 02-samples/16-lambda-error-analysis-agent/cdk/lambda/sample-business-function/lambda_function.py
  • ... and 21 more files

Security Scan Results

Critical High Medium Low Info
0 0 0 0 0

Threshold: High

No security issues detected in your changes. Great job!

This scan only covers files changed in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant