Skip to content

avantikarathi01/ai-chatbot

Repository files navigation

✨ AI Chatbot — AWS Serverless AI Assistant

A fully serverless AI chatbot built on AWS using Lambda, Amazon Bedrock (Nova Lite), DynamoDB, API Gateway, and a static HTML frontend hosted on S3.


🔗 Live Demo

Frontend hosted on AWS S3 Static Website Hosting
API powered by Amazon API Gateway + Lambda + Bedrock


📌 Table of Contents

  1. Project Overview
  2. Architecture
  3. Folder Structure
  4. Services Used
  5. Step-by-Step Setup From Scratch
  6. API Reference
  7. Troubleshooting
  8. Future Improvements
  9. Resume Description

Project Overview

AI is a serverless conversational AI chatbot that:

  • Accepts user messages from a browser-based chat UI
  • Sends them to Amazon Bedrock (Nova Lite model) for AI-generated responses
  • Stores full conversation history in DynamoDB per session
  • Returns AI replies back to the frontend in real time

No servers to manage. No infrastructure to maintain. 100% AWS serverless.


Architecture

User (Browser)
     │
     ▼
HTML Frontend (S3 Static Website)
     │  HTTP POST /chat
     ▼
Amazon API Gateway  (REST API)
     │
     ▼
AWS Lambda  (Python 3.12)
     │              │
     ▼              ▼
Amazon Bedrock    DynamoDB
(Nova Lite AI)  (chat-history)
     │
     ▼
Lambda returns AI reply
     │
     ▼
API Gateway → Frontend → User sees response

Full flow: User → S3 Frontend → API Gateway → Lambda → Bedrock → DynamoDB → Lambda → API Gateway → User


Folder Structure

ai-chatbot/
│
├── index.html                  # Frontend chat UI (deployed to S3)
│
├── lambda/
│   └── lambda_function.py      # Lambda function (Python)
│
├── docs/
│   └── screenshots/
│       ├── 01-iam-role.png          # placeholder
│       ├── 02-dynamodb-table.png    # placeholder
│       ├── 03-lambda-function.png   # placeholder
│       ├── 04-bedrock-access.png    # placeholder
│       ├── 05-api-gateway.png       # placeholder
│       ├── 
│       ├── 06-s3-hosting.png        # placeholder
│       ├── 07-hoppscotch-test.png   # placeholder
│       └── 08-chat-ui.png           # placeholder
│
├── README.md                   # This file
├── ARCHITECTURE.md             # Detailed architecture + flowchart
├── TROUBLESHOOTING.md          # Common errors and fixes
├── FUTURE_IMPROVEMENTS.md      # Roadmap
└── RESUME.md                   # Resume-ready project description

Services Used

Service Purpose
AWS Lambda Runs backend logic (Python)
Amazon Bedrock (Nova Lite) Generates AI responses
Amazon DynamoDB Stores chat history per session
Amazon API Gateway Exposes REST API endpoint
Amazon S3 Hosts static HTML frontend
AWS IAM Manages permissions and roles
Hoppscotch / Postman API testing

Step-by-Step Setup From Scratch


Step 1 — AWS Account Setup

  1. Go to https://aws.amazon.com and click Create an AWS Account
  2. Enter your email, set a root password, and complete billing setup
  3. Verify your identity (phone + credit card required — free tier available)
  4. Sign in to the AWS Management Console

📸 Screenshot placeholder: docs/screenshots/01-aws-console.png


Step 2 — Region Selection

  1. In the top-right corner of the AWS Console, click the region dropdown
  2. Select US East (N. Virginia) — us-east-1

⚠️ Important: All services (Lambda, DynamoDB, Bedrock, API Gateway) must be in the same region: us-east-1


Step 3 — IAM Role Creation

The Lambda function needs permission to call Bedrock and DynamoDB.

  1. Go to IAM → Roles → Create Role
  2. Select Trusted entity type: AWS Service
  3. Select Use case: Lambda → click Next
  4. Attach these policies:
    • AmazonDynamoDBFullAccess
    • AmazonBedrockFullAccess
    • AWSLambdaBasicExecutionRole
  5. Name the role: ai-lambda-role
  6. Click Create Role

📸 Screenshot placeholder: docs/screenshots/01-iam-role.png


Step 4 — DynamoDB Table Creation

  1. Go to DynamoDB → Tables → Create Table
  2. Fill in:
    • Table name: chat-history
    • Partition key: session_id (String)
    • Sort key: timestamp (String)
  3. Leave all other settings as default
  4. Click Create Table
  5. Wait until the table status shows Active

📸 Screenshot placeholder: docs/screenshots/02-dynamodb-table.png


Step 5 — Lambda Function Creation

  1. Go to Lambda → Functions → Create Function
  2. Select Author from scratch
  3. Fill in:
    • Function name: ai-chatbot
    • Runtime: Python 3.12
    • Architecture: x86_64
  4. Under Permissions, choose Use an existing role → select nova-ai-lambda-role
  5. Click Create Function

Upload the code:

  1. In the Lambda code editor, delete the default code
  2. Copy the full contents of lambda/lambda_function.py and paste it
  3. Click Deploy

Increase timeout:

  1. Go to Configuration → General Configuration → Edit
  2. Set Timeout to 30 seconds
  3. Click Save

📸 Screenshot placeholder: docs/screenshots/03-lambda-function.png


Step 6 — Bedrock Model Access Setup

  1. Go to Amazon Bedrock → Model Access (left sidebar)
  2. Click Manage Model Access
  3. Find Amazon Nova Lite in the list
  4. Check the checkbox next to it
  5. Click Request Model Access
  6. Wait for status to change to Access Granted (usually instant)

📸 Screenshot placeholder: docs/screenshots/04-bedrock-access.png

⚠️ If you skip this step, Lambda will throw a AccessDeniedException when calling Bedrock.


Step 7 — API Gateway Creation

  1. Go to API Gateway → Create API
  2. Choose REST API → click Build
  3. Select New API
  4. Fill in:
    • API name: ai-api
    • Endpoint Type: Regional
  5. Click Create API

Create Resource:

  1. Click Actions → Create Resource
  2. Resource name: chat
  3. Resource path: /chat
  4. ✅ Enable CORS checkbox
  5. Click Create Resource

Create POST Method:

  1. Select /chat resource → Actions → Create Method → POST
  2. Integration type: Lambda Function
  3. Lambda Function: ai-chatbot
  4. Click Save → click OK on the permission popup

Enable CORS:

  1. Select /chatActions → Enable CORS
  2. Click Enable CORS and replace existing CORS headers
  3. Click Yes, replace existing values

Deploy API:

  1. Actions → Deploy API
  2. Deployment stage: [New Stage]
  3. Stage name: prod
  4. Click Deploy
  5. Copy the Invoke URL — it will look like: https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/chat

📸 Screenshot placeholder: docs/screenshots/05-api-gateway.png


Step 8 — Resource Policy Setup

This policy allows public access to your API endpoint.

  1. In API Gateway, go to your API → Resource Policy
  2. Paste the following JSON (replace the ARN values with your own):
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "execute-api:Invoke",
      "Resource": "arn:aws:execute-api:us-east-1:<YOUR_ACCOUNT_ID>:<YOUR_API_ID>/prod/POST/chat"
    },
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "execute-api:Invoke",
      "Resource": "arn:aws:execute-api:us-east-1:<YOUR_ACCOUNT_ID>:<YOUR_API_ID>/prod/OPTIONS/chat"
    }
  ]
}
  1. Click Save
  2. Re-deploy the API (Actions → Deploy API → prod stage)

📸 Screenshot placeholder: docs/screenshots/06-resource-policy.png

⚠️ You must redeploy after saving the resource policy, otherwise changes won't take effect.


Step 9 — S3 Static Website Hosting

  1. Go to S3 → Create Bucket
  2. Fill in:
    • Bucket name: ai-frontend (must be globally unique)
    • Region: us-east-1
  3. Uncheck "Block all public access" → confirm the warning
  4. Click Create Bucket

Enable Static Website Hosting:

  1. Open the bucket → Properties tab
  2. Scroll to Static website hosting → click Edit
  3. Enable it, set:
    • Index document: index.html
  4. Click Save changes

Upload index.html:

  1. Go to Objects tab → Upload
  2. Upload your index.html file
  3. Click Upload

Set Bucket Policy (public read):

  1. Go to Permissions tab → Bucket Policy → Edit
  2. Paste:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::nova-ai-frontend/*"
    }
  ]
}
  1. Click Save changes
  2. Copy the Bucket website endpoint URL from the Properties tab

📸 Screenshot placeholder: docs/screenshots/07-s3-hosting.png


Step 10 — Testing with Hoppscotch / Postman

Before opening the frontend, test the API directly.

Using Hoppscotch (free, browser-based):

  1. Go to https://hoppscotch.io
  2. Set method to POST
  3. Enter your API URL:
    https://<YOUR_API_ID>.execute-api.us-east-1.amazonaws.com/prod/chat
    
  4. Go to Body tab → select JSON
  5. Paste:
    {
      "message": "Hello! What is AWS Lambda?",
      "session_id": "test-session-001"
    }
  6. Click Send

Expected Response:

{
  "statusCode": 200,
  "body": "{\"message\": \"AWS Lambda is a serverless compute service...\", \"session_id\": \"test-session-001\"}"
}

📸 Screenshot placeholder: docs/screenshots/08-hoppscotch-test.png


Step 11 — Frontend Integration

The index.html file already has the API URL hardcoded. If you deployed your own API, update line in index.html:

const API = "https://<YOUR_API_ID>.execute-api.us-east-1.amazonaws.com/prod/chat"

Replace with your own Invoke URL from Step 7.

Then re-upload index.html to S3 and open the bucket website URL in your browser.

📸 Screenshot placeholder: docs/screenshots/09-chat-ui.png


API Reference

Endpoint

POST https://<api-id>.execute-api.us-east-1.amazonaws.com/prod/chat

Request

{
  "message": "What is Amazon Bedrock?",
  "session_id": "user-abc123"
}
Field Type Required Description
message string Yes The user's chat message
session_id string No Unique session ID (auto-generated if omitted)

Response

{
  "statusCode": 200,
  "body": "{\"message\": \"Amazon Bedrock is a fully managed service...\", \"session_id\": \"user-abc123\"}"
}
Field Type Description
statusCode number HTTP status code
body.message string AI-generated reply
body.session_id string Session ID echoed back

Troubleshooting

See TROUBLESHOOTING.md for detailed fixes.

Error Likely Cause Fix
AccessDeniedException on Bedrock Model access not granted Go to Bedrock → Model Access → Enable Nova Lite
ResourceNotFoundException on DynamoDB Table name mismatch Ensure table is named exactly chat-history
CORS error in browser CORS not enabled on API Gateway Re-enable CORS and redeploy API
502 Bad Gateway Lambda crash Check Lambda CloudWatch logs
API returns empty response Lambda timeout Increase Lambda timeout to 30s
S3 page shows 403 Bucket not public Check bucket policy and unblock public access

Future Improvements

See FUTURE_IMPROVEMENTS.md for full roadmap.

  • Add user authentication with Amazon Cognito
  • Switch to streaming responses for real-time typing effect
  • Add support for multiple Bedrock models (Claude, Titan, etc.)
  • Deploy frontend with CloudFront CDN for HTTPS + performance
  • Add conversation export (download chat as PDF/text)
  • Implement rate limiting on API Gateway
  • Add voice input using Amazon Transcribe

Resume Description

See RESUME.md for the full resume-ready write-up.

AI Chatbot** — Built a fully serverless AI chatbot on AWS using Lambda (Python), Amazon Bedrock (Nova Lite LLM), DynamoDB for persistent chat history, API Gateway REST API, and S3 static website hosting. Implemented session-based conversation memory, CORS-enabled API, and a responsive HTML/CSS/JS frontend. Reduced infrastructure cost to near-zero using AWS free tier serverless architecture.


About

This project Nova AI is a fully serverless conversational chatbot built on AWS that delivers real-time AI-powered responses. It accepts user input from a browser-based interface, processes it using Amazon Bedrock (Nova Lite model), and stores complete conversation history in DynamoDB for each session.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors