A production-ready REST API chatbot powered by AWS Bedrock (Amazon Nova AI), DynamoDB, and FastAPI.
- π RESTful API - FastAPI with automatic documentation (Swagger UI)
- π€ Amazon Nova AI - Fast, cost-effective, no access forms required
- πΎ DynamoDB Storage - Persistent conversation history
- π Session Management - Multi-user support
- βοΈ Easy Configuration - Change models via
.envfile - π Auto Documentation - Built-in Swagger UI at
/docs - π³ Docker Ready - Containerized deployment
- βοΈ AWS Lambda - Serverless deployment option β TESTED
- βΈοΈ AWS EKS - Kubernetes deployment option β TESTED
# Windows
install.bat
# Manual
pip install -r requirements.txtOption A: Create .env file (Recommended)
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
AWS_REGION=us-east-1
BEDROCK_MODEL_ID=us.amazon.nova-pro-v1:0
DYNAMODB_TABLE_NAME=ChatbotConversationsImportant: Use region-prefixed model IDs (e.g., us.amazon.nova-pro-v1:0 not amazon.nova-pro-v1:0)
Option B: Use AWS CLI
aws configure- Go to: https://console.aws.amazon.com/bedrock/
- Click "Model access" in sidebar
- Click "Manage model access"
- Check: β Amazon Nova Pro (and optionally Lite/Micro)
- Click "Save changes"
- Wait 1-2 minutes (instant approval, no forms!)
python setup_dynamodb.pypython api.pyServer starts at: http://localhost:8000
Open your browser: http://localhost:8000/docs
Or use cURL:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello! What is AWS Bedrock?"}'Once the server is running:
- Swagger UI: http://localhost:8000/docs (Try it out!)
- ReDoc: http://localhost:8000/redoc (Clean docs)
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| POST | /chat |
Send a message to the chatbot |
| GET | /history/{session_id} |
Get conversation history |
| GET | /sessions |
List active sessions |
| POST | /models/list |
List available AWS Bedrock models |
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Explain AWS Lambda in simple terms"
}'Response:
{
"response": "AWS Lambda is a serverless compute service...",
"session_id": "abc123-def456",
"model": "amazon.nova-pro-v1:0",
"region": "us-east-1",
"timestamp": "2024-01-20T10:30:00Z"
}Edit .env file:
# Use Nova Lite (faster, cheaper)
BEDROCK_MODEL_ID=us.amazon.nova-lite-v1:0
# Use Nova Micro (fastest, cheapest)
BEDROCK_MODEL_ID=us.amazon.nova-micro-v1:0
# Use Nova Pro (balanced, default)
BEDROCK_MODEL_ID=us.amazon.nova-pro-v1:0Note: Amazon Nova models require region-prefixed IDs (us., eu., etc.)
Restart the API after changing.
See all available models:
curl -X POST http://localhost:8000/models/listcurl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Hello!",
"model_id": "us.amazon.nova-micro-v1:0"
}'import requests
# Send a message
response = requests.post(
"http://localhost:8000/chat",
json={"message": "What is AWS?"}
)
print(response.json()['response'])
# Continue conversation
response2 = requests.post(
"http://localhost:8000/chat",
json={
"message": "Tell me more",
"session_id": response.json()['session_id']
}
)We provide a ready-to-use test client:
# Run demo
python test_api_client.py demo
# Interactive chat mode
python test_api_client.py interactive
# Test multiple sessions
python test_api_client.py sessions
# List available models
python test_api_client.py modelslangchain/
βββ api.py # Main FastAPI server β
βββ chatbot_aws.py # AWS Bedrock integration
βββ setup_dynamodb.py # DynamoDB setup script
βββ test_api_client.py # Python API client
βββ requirements.txt # Python dependencies
βββ .env # Configuration (create this)
βββ .gitignore # Git ignore rules
β
βββ deployment/ # Deployment files
β βββ Dockerfile # Docker container
β βββ docker-compose.yml # Docker Compose
β βββ lambda_handler.py # AWS Lambda handler
β βββ lambda_deploy.py # Lambda deployment
β βββ cloudformation_template.yaml
β
βββ docs/ # Documentation
β βββ API_EXAMPLES.md # Complete API guide
β βββ ENABLE_AMAZON_NOVA.md # AWS setup guide
β βββ CHANGE_MODEL.md # Model configuration
β
βββ scripts/ # Helper scripts
βββ run_api.bat # Quick start (Windows)
βββ install.bat # Dependency installer
cd deployment
docker-compose upOr manually:
docker build -f deployment/Dockerfile -t chatbot-api .
docker run -p 8000:8000 --env-file .env chatbot-apicd deployment
python lambda_deploy.pyFollow the prompts to deploy to AWS Lambda + API Gateway.
| Model | Cost/1K Messages | Speed | Quality |
|---|---|---|---|
| Nova Micro | ~$0.17 | β‘β‘β‘ | βββ |
| Nova Lite | ~$0.30 | β‘β‘ | ββββ |
| Nova Pro | ~$4.00 | β‘ | βββββ |
Plus:
- DynamoDB: ~$0.05 per 1,000 messages
- API calls are free when testing locally
Free Tier:
- Lambda: 1M requests/month (forever!)
- DynamoDB: 25GB storage + 25 read/write capacity units
# Check your .env file
cat .env
# Or verify AWS credentials
aws sts get-caller-identity- Go to: https://console.aws.amazon.com/bedrock/
- Enable Amazon Nova models (instant approval!)
- Wait 2 minutes and restart API
python setup_dynamodb.py# Windows: Find and kill the process
netstat -ano | findstr :8000
taskkill /PID <pid> /F
# Or use a different port
uvicorn api:app --port 8001- Check logs in the terminal running
api.py - Verify AWS credentials in
.env - Ensure DynamoDB table exists
- Confirm Bedrock models are enabled
- Quick Start:
START_HERE.md- New to the project? Start here! - API Examples:
docs/API_EXAMPLES.md - Model Configuration:
docs/CHANGE_MODEL.md - Model IDs Reference:
docs/MODEL_IDS.mdβ (Important!) - AWS Setup:
docs/ENABLE_AMAZON_NOVA.md
- Deployment Overview:
docs/DEPLOYMENT_SUMMARY.md- Quick reference - Deployment Guide:
deployment/README.md- Choose your method - AWS Lambda:
deployment/DEPLOY_LAMBDA.md- Serverless - Kubernetes (EKS):
deployment/DEPLOY_KUBERNETES.md- Production - Architecture:
deployment/ARCHITECTURE.md- System design
- Testing Guide:
docs/TESTING_GUIDE.md- Test local & AWS deployments - Project Structure:
docs/PROJECT_STRUCTURE.md- File organization - Cleanup Summary:
docs/CLEANUP_SUMMARY.md- What was changed
# Start API
python api.py
# In another terminal - test
python test_api_client.py interactiveCreate a .env file:
AWS_ACCESS_KEY_ID=xxx
AWS_SECRET_ACCESS_KEY=xxx
AWS_REGION=us-east-1
BEDROCK_MODEL_ID=amazon.nova-pro-v1:0
DYNAMODB_TABLE_NAME=ChatbotConversations- Python 3.8+
- AWS Account with Bedrock access
- AWS credentials configured
β
No Access Forms - Instant approval
β
Lower Cost - Up to 4x cheaper than alternatives
β
Fast Performance - Quick responses
β
Multimodal - Nova Pro supports images
β
Built by AWS - Native integration
- AWS Bedrock: https://aws.amazon.com/bedrock/
- FastAPI Docs: https://fastapi.tiangolo.com/
- LangChain: https://python.langchain.com/
MIT License - Feel free to use and modify!
Suggestions and improvements welcome! Key areas:
- Streaming responses
- Authentication/Authorization
- Rate limiting
- Response caching
- Multi-modal support (images)
- Conversation summarization
Built with AWS βοΈ | Powered by Amazon Nova π€ | Production-Ready π
Quick Start: install.bat β Configure .env β python api.py β Visit http://localhost:8000/docs