Skip to content

DEVANAND-JAYARAMAN/CodeMentor-AI-AWS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Chatbot with Amazon Bedrock

Serverless AI chatbot powered by Amazon Bedrock Titan models with a responsive web interface

✨ Features

  • πŸ€– AI-Powered Conversations - Intelligent responses using Amazon Bedrock Titan models
  • ⚑ Serverless Architecture - Scalable and cost-effective AWS infrastructure
  • 🌐 RESTful API - Clean API Gateway integration with CORS support
  • πŸ“± Responsive Web Interface - Modern HTML/CSS/JavaScript frontend
  • πŸ” Secure Access - IAM roles and permissions for secure operations
  • πŸ’¬ Real-time Chat - Interactive conversational interface

πŸ—οΈ Architecture Overview

πŸ—οΈ AWS Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AWS Amplify   β”‚    β”‚  Amazon S3      β”‚    β”‚  API Gateway    β”‚
β”‚   (CI/CD +      β”‚    β”‚  (Static        β”‚    β”‚  (REST API +    β”‚
β”‚    Hosting)     β”‚    β”‚   Assets)       β”‚    β”‚    CORS)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   AWS Lambda    β”‚    β”‚  Amazon Bedrock β”‚    β”‚      IAM        β”‚
         β”‚  (Python 3.14)  │───▢│  (Titan LLM)   β”‚     β”‚  (Roles &        β”‚
         β”‚   Function      β”‚    β”‚                 β”‚    β”‚ Permissions)    β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The chatbot follows a serverless architecture pattern using AWS managed services:

πŸ”„ Request Flow

  1. User Interface - Static web frontend hosted on S3/Amplify
  2. API Gateway - Handles HTTPS requests with CORS configuration
  3. Lambda Function - Processes requests and manages Bedrock integration
  4. Amazon Bedrock - Provides AI inference using Titan models
  5. IAM Roles - Ensures secure service-to-service communication

🎯 Architecture Benefits

  • Serverless - No infrastructure management required
  • Scalable - Automatically handles traffic spikes
  • Cost-Effective - Pay only for actual usage
  • Secure - IAM-based access control
  • Reliable - Built on AWS managed services

πŸ› οΈ Tech Stack

AWS Service Purpose
πŸ” IAM Role-based access control and security
⚑ Lambda Serverless backend processing (Python 3.12)
🌐 API Gateway RESTful API with CORS support
πŸ€– Bedrock AI inference using Titan Text model
πŸ“¦ S3 Static website hosting and asset storage
πŸš€ Amplify CI/CD deployment and hosting

Frontend: HTML5, CSS3, JavaScript ES6+, Web Speech API

πŸš€ Quick Start

Prerequisites

  • AWS Account with appropriate permissions
  • Modern web browser

Deploy to AWS

  1. Clone Repository

    git clone https://github.com/julien-muke/bedrock-chatbot.git
    cd bedrock-chatbot
  2. Set Up IAM Role

    • Create execution role for Lambda
    • Attach policies: AmazonBedrockFullAccess, CloudWatchLogsFullAccess
  3. Deploy Lambda Function

    • Runtime: Python 3.12
    • Handler: lambda_function.lambda_handler
    • Timeout: 30 seconds
    • Attach IAM role from step 2
  4. Configure API Gateway

    • Create REST API
    • Add /chat resource with POST method
    • Enable CORS for all origins
    • Deploy to dev stage
  5. Enable Amazon Bedrock

    • Request access to amazon.titan-text-express-v1 model
    • Ensure your region supports Bedrock
  6. Deploy Frontend

    • Option A: Upload index.html to S3 with static hosting
    • Option B: Deploy with AWS Amplify for CI/CD
  7. Update API Endpoint

    // In index.html, replace with your API Gateway URL
    const API_URL = 'https://your-api-id.execute-api.region.amazonaws.com/dev/chat';

πŸ’‘ Usage Examples

The chatbot can handle various types of conversations and queries:

// General Conversations
"Hello, how are you today?"
"Tell me about artificial intelligence"
"What's the weather like?"

// Technical Questions
"Explain machine learning basics"
"How does cloud computing work?"
"What are the benefits of serverless architecture?"

// Creative Tasks
"Write a short story about robots"
"Help me brainstorm project ideas"
"Create a simple poem about technology"

βš™οΈ Configuration

Lambda Environment Variables

import os

BEDROCK_REGION = os.environ.get('AWS_REGION', 'us-east-1')
MODEL_ID = 'amazon.titan-text-express-v1'
MAX_TOKENS = 500
TEMPERATURE = 0.7

API Gateway Settings

  • Method: POST
  • Resource: /chat
  • CORS: Enabled for *
  • Integration: Lambda Function
  • Stage: dev

Frontend Configuration

const CONFIG = {
  API_ENDPOINT: 'https://your-api-gateway.amazonaws.com/dev/chat',
  BEDROCK_MODEL: 'amazon.titan-text-express-v1',
  MAX_TOKENS: 500,
  TEMPERATURE: 0.7
};

πŸ“ Project Structure

AI-Chatbot/
β”œβ”€β”€ index.html              # Frontend web interface
β”œβ”€β”€ lambda_function.py      # AWS Lambda backend function
β”œβ”€β”€ s3-bucket-policy.json   # S3 bucket policy configuration
β”œβ”€β”€ METRICS.md              # Performance metrics and analytics
└── README.md               # Project documentation

πŸ“± Browser Support

Feature Chrome Safari Firefox Edge
Modern JavaScript βœ… βœ… βœ… βœ…
CSS Grid/Flexbox βœ… βœ… βœ… βœ…
Fetch API βœ… βœ… βœ… βœ…
Mobile Responsive βœ… βœ… βœ… βœ…

πŸ”§ Development

Local Development

# Serve locally
python -m http.server 8080

# Test API endpoint
curl -X POST https://your-api-gateway.amazonaws.com/dev/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello", "history": []}'

AWS Costs

  • Lambda: Pay per request (~$0.20 per 1M requests)
  • API Gateway: Pay per API call (~$3.50 per 1M calls)
  • Bedrock: Pay per token (~$0.0008 per 1K tokens)
  • S3: Pay per storage (~$0.023 per GB/month)
  • Amplify: Free tier available

πŸ”’ Security Features

  • βœ… IAM Roles: Least privilege access
  • βœ… CORS Protection: Configured for secure cross-origin requests
  • βœ… Input Validation: Sanitized user inputs
  • βœ… HTTPS Only: All communications encrypted
  • βœ… No Data Persistence: User conversations not stored server-side

πŸ“ˆ Performance

  • ⚑ Response Time: < 2 seconds average
  • πŸ“± Mobile Score: 95+ Lighthouse performance
  • πŸ”„ Availability: 99.9% (AWS SLA)
  • πŸ’° Cost Efficiency: Serverless pay-per-use model

🀝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/name
  3. Commit changes: git commit -m 'Add feature'
  4. Push to branch: git push origin feature/name
  5. Submit pull request

πŸ“œ License

MIT License - see LICENSE file for details.


⭐ Star this repo if it helped you learn programming!

Built with ❀️ using AWS serverless technologies

Copyright Β© 2025 Dev Anand Jayaraman. All rights reserved.

About

AI-powered chatbot built with AWS Bedrock and Lambda, featuring a responsive web interface for intelligent conversations

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors