DEV Community

Basel Mohamed Alam
Basel Mohamed Alam

Posted on

🎓 Building an AI-Powered Study Buddy with AWS (Bedrock + Lambda)

Flow Chart

Transform Your Study Materials into Interactive Quizzes with Claude AI
Have you ever wished you could instantly generate quiz questions from your study materials? In this tutorial, I'll show you how to build a fully functional AI-powered study assistant using AWS services. This project is perfect for learning serverless architecture and working with generative AI!

🚀 What We're Building
Study Buddy is an AI-powered application that:

✅ Accepts study materials (PDFs, images, text files)
✅ Extracts text using OCR (Amazon Textract)
✅ Generates customized quiz questions using Claude AI (Amazon Bedrock)
✅ Allows users to specify difficulty level and question count
✅ Provides explanations for correct answers

Repository
https://github.com/basel5001/Study-buddy

🏗️ Architecture Overview

📌 Project Overview

Study Buddy is an AI-powered application that transforms study materials into interactive quiz questions. Students can upload documents, extract text, and get customized quizzes generated by Claude AI.

🎯 Key Features

  • Document Upload - Accept PDFs, images, and text files
  • Smart Text Extraction - OCR capability using Amazon Textract
  • AI Quiz Generation - Claude AI creates intelligent questions
  • Customizable Settings - Choose difficulty (easy/medium/hard) and number of questions
  • Interactive Quiz Interface - Answer questions and get instant feedback
  • Detailed Explanations - Learn why answers are correct
  • Score Tracking - See your performance immediately

🏗️ System Architecture

Components:

  1. Frontend (React)

    • User interface for uploading materials
    • Quiz taking interface
    • Results dashboard
  2. API Layer (API Gateway)

    • /upload - Handle document uploads
    • /extract - Process text extraction
    • /generate-quiz - Generate quiz questions
  3. Processing Layer (AWS Lambda)

    • Function 1: Extract text from documents
    • Function 2: Generate quiz using AI
  4. AI Services

    • Amazon Textract: OCR and text extraction
    • Amazon Bedrock (Claude): Intelligent quiz generation
  5. Storage (S3)

    • Store uploaded documents
  6. Monitoring (CloudWatch)

    • Track logs, errors, and performance metrics

🔄 User Flow
Step 1: Upload Study Material

  • User uploads a document (PDF/image) or pastes text
  • File is stored in S3 bucket

Step 2: Extract Text

  • Lambda function retrieves document from S3
  • Amazon Textract extracts all text content
  • Extracted text is displayed to user for review

Step 3: Generate Quiz

  • User selects preferences:
    • Number of questions (1-20)
    • Difficulty level (easy/medium/hard)
    • Question type (multiple choice)
  • Text is sent to second Lambda function
  • Claude AI generates customized quiz questions with:
    • Question text
    • 4 multiple choice options
    • Correct answer
    • Explanation

Step 4: Take Quiz

  • User answers questions interactively
  • Selections are tracked in real-time
  • Submit when ready

Step 5: View Results

  • See correct/incorrect answers highlighted
  • Read explanations for each question
  • View final score and percentage
  • Option to generate new quiz

💰 Cost Breakdown (Monthly Estimates)
Light Usage (10 quizzes/day):

  • Bedrock (Claude): ~$3-5/month
  • Textract: ~$1-2/month
  • Lambda: Free tier (negligible)
  • S3 Storage: ~$0.50/month
  • API Gateway: ~$1/month
  • Total: ~$6-10/month

Medium Usage (100 quizzes/day):

  • Bedrock: ~$30-50/month
  • Textract: ~$10-15/month
  • Lambda: ~$5/month
  • Other services: ~$5/month
  • Total: ~$50-75/month

🛠️ AWS Services Used

Service Purpose Why This Service
S3 Document storage Cheap, reliable, easy Lambda integration
Lambda Serverless compute No server management, pay per use
API Gateway REST API endpoints Managed API with built-in security
Bedrock AI text generation Access to Claude without managing infrastructure
Textract OCR/text extraction Purpose-built for document processing
CloudWatch Logging & monitoring Native AWS monitoring solution

🎨 Design Decisions
Why Serverless?

  • No server maintenance
  • Auto-scaling
  • Pay only for what you use
  • Perfect for sporadic usage patterns

Why Claude (Bedrock)?

  • Excellent at following instructions
  • Consistent JSON output
  • Strong reasoning for educational content
  • No need to manage API keys separately

Why React Frontend?

  • Component-based architecture
  • Easy state management
  • Fast development
  • Great user experience

📊 Technical Highlights
Lambda Function 1: Text Extraction

  • Trigger: API Gateway POST request
  • Process: Fetch document → Textract → Extract lines
  • Output: Clean text ready for processing
  • Timeout: 30 seconds
  • Memory: 512 MB

Lambda Function 2: Quiz Generation

  • Trigger: API Gateway POST request
  • Process: Format prompt → Call Bedrock → Parse JSON
  • Output: Structured quiz questions array
  • Timeout: 60 seconds
  • Memory: 1024 MB

API Gateway Configuration

  • Type: REST API
  • Authentication: None (can add API keys)
  • CORS: Enabled for browser access
  • Rate Limiting: Optional (10 req/sec recommended)
  • Stage: Production

🚀 Deployment Workflow
Setup Phase:

  1. Enable Bedrock model access
  2. Create S3 bucket
  3. Create IAM roles with proper permissions
  4. Deploy Lambda functions
  5. Configure API Gateway
  6. Deploy React frontend

Testing Phase:

  1. Test each Lambda function individually
  2. Test API endpoints with Postman/cURL
  3. Verify CORS configuration
  4. Test complete user flow
  5. Monitor CloudWatch logs

Production Phase:

  1. Add custom domain (optional)
  2. Enable CloudWatch alarms
  3. Set up usage plans and API keys
  4. Configure backup strategies
  5. Monitor costs and usage

🎓 Learning Outcomes
Skills Gained:

  • ✅ Serverless architecture patterns
  • ✅ AWS service integration
  • ✅ AI/ML API integration
  • ✅ Prompt engineering for LLMs
  • ✅ RESTful API design
  • ✅ Error handling in distributed systems
  • ✅ CORS configuration
  • ✅ React state management

Best Practices Applied:

  • Separation of concerns (frontend/backend)
  • Stateless Lambda functions
  • Proper error handling and logging
  • Environment variable usage
  • Security through IAM roles
  • Cost optimization strategies

🔮 Future Enhancements
Phase 1: Core Improvements

  • Add user authentication (AWS Cognito)
  • Store quiz history in DynamoDB
  • Support more file formats (DOCX, PPT)
  • Add true/false and fill-in-blank questions

Phase 2: Advanced Features

  • Spaced repetition algorithm
  • Study session tracking
  • Progress analytics dashboard
  • Collaborative study groups
  • Flashcard generation

Phase 3: Scale & Optimize

  • Mobile app (React Native)
  • Offline mode capability
  • Export to PDF/Anki
  • AI tutor chat interface
  • Voice mode with Amazon Polly

🐛 Common Challenges & Solutions
Challenge 1: CORS Errors

  • Problem: Browser blocks API requests
  • Solution: Enable CORS in API Gateway + return headers in Lambda

Challenge 2: JSON Parsing from AI

  • Problem: Claude wraps JSON in markdown
  • Solution: Use regex to extract pure JSON before parsing

Challenge 3: Token Limits

  • Problem: Large documents exceed limits
  • Solution: Truncate text to 4000 characters or chunk processing

Challenge 4: Timeout Errors

  • Problem: Lambda times out during processing
  • Solution: Increase timeout to 60s and optimize code

Challenge 5: Bedrock Access

  • Problem: "Access Denied" errors
  • Solution: Request model access in Bedrock console first

📈 Success Metrics
Technical Metrics:

  • Average response time: < 5 seconds
  • Error rate: < 1%
  • Quiz generation success: > 95%
  • Text extraction accuracy: > 90%

User Metrics:

  • Quiz completion rate
  • Average score improvement over time
  • Daily active users
  • Quiz variety (different subjects)

🎯 Key Takeaways
What Worked Well:

  • Serverless architecture kept costs low
  • Claude AI produced high-quality questions consistently
  • React provided smooth user experience
  • AWS services integrated seamlessly

What Could Be Improved:

  • Add caching for repeated requests
  • Implement batch processing for multiple documents
  • Add more question types
  • Better mobile responsiveness

Business Potential:

  • SaaS model for students/teachers
  • B2B sales to educational institutions
  • Premium features (advanced analytics, unlimited quizzes)
  • White-label solution for EdTech companies

📚 Resources & Next Steps
Documentation:

  • AWS Lambda Best Practices
  • Bedrock API Reference
  • React State Management
  • Prompt Engineering Guide

Next Steps:

  1. Deploy a demo version
  2. Gather user feedback
  3. Iterate on features
  4. Write comprehensive tests
  5. Create video tutorial
  6. Launch on Product Hunt

💡 Pro Tips

  • Start with the free tier to minimize costs
  • Use CloudWatch extensively for debugging
  • Test each component independently first
  • Keep prompts simple and clear
  • Always handle errors gracefully
  • Document your API endpoints
  • Version your Lambda functions
  • Set up alarms for critical metrics

🌟 Project Impact
For Students:

  • Faster exam preparation
  • Better retention through active recall
  • Personalized learning experience
  • Study anywhere, anytime

For Developers:

  • Real-world serverless experience
  • AI integration portfolio piece
  • Cloud architecture knowledge
  • Full-stack development practice

Total Build Time: ~8-12 hours
Difficulty Level: Intermediate
Tech Stack Complexity: Medium
Scalability: High
Maintenance: Low

Top comments (0)