Skip to content

๐Ÿฅ Production-ready AWS Health Advice Chatbot with Lambda fulfillment, Lex v2 NLU, and full voice integration. Features dynamic health advice generation, speech-to-text/text-to-speech capabilities, and Infrastructure as Code deployment. Built with React, Python Lambda, and Terraform.

License

Notifications You must be signed in to change notification settings

abaasi256/AWS-Health-Advice-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฅ AWS Health Advice Chatbot

Production-ready serverless health advice application powered by AWS Lex v2 with Lambda fulfillment and full voice support

AWS Terraform React Lambda Voice License: MIT

๐Ÿ“‹ Overview

The AWS Health Advice Chatbot is a comprehensive portfolio project that demonstrates advanced cloud engineering and modern frontend development skills. Built with AWS Lex v2 for natural language understanding, Lambda fulfillment for dynamic responses, and complete voice integration for an immersive user experience.

๐ŸŽฏ Key Features

  • โšก Lambda Fulfillment - Dynamic health advice generation with personalized responses
  • ๐ŸŽค Full Voice Support - Complete speech-to-text and text-to-speech capabilities
  • ๐Ÿค– Intelligent Conversations - Natural language processing with AWS Lex v2
  • ๐Ÿ—๏ธ Infrastructure as Code - Complete Terraform automation
  • ๐Ÿ”’ Enterprise Security - IAM least-privilege and proper Lambda permissions
  • ๐Ÿ“ฑ Modern Frontend - Responsive React application with voice controls
  • ๐Ÿ’ฐ Cost Optimized - Efficient Lambda execution with minimal AWS resource usage

๐ŸŽค Voice Features

โœ… Complete Voice Experience

  • ๐Ÿ”Š Text-to-Speech - All bot responses spoken aloud with auto-play
  • ๐ŸŽค Speech-to-Text - Speak your health questions directly
  • ๐Ÿ”‡ Voice Controls - Toggle voice on/off, individual message replay
  • ๐Ÿ‘‚ Smart Listening - Visual feedback during voice input
  • ๐Ÿ“ฑ Mobile Voice - Full voice support on mobile browsers
  • โ™ฟ Accessible - Screen reader compatible with ARIA labels

๐ŸŽฏ Voice Interaction Demo

๐Ÿ‘ค User: [Clicks microphone] "How much water should I drink?"
๐ŸŽค App: [Converts speech to text in input field]
๐Ÿ‘ค User: [Presses Enter to send]
๐Ÿค– Bot: [Lambda generates dynamic health advice]
๐Ÿ”Š App: [Automatically speaks response aloud]

๐ŸŒ Browser Voice Support

Browser Speech Recognition Text-to-Speech Overall
Chrome โœ… Excellent โœ… Excellent โญโญโญโญโญ
Safari โœ… Good โœ… Good โญโญโญโญ
Edge โœ… Good โœ… Good โญโญโญโญ
Firefox โŒ Limited โœ… Basic โญโญ

๐Ÿ“Š Architecture Flow

AWS Health Advice Chatbot Architecture AWS architecture diagram showing the complete serverless flow from React frontend through Lex v2, Lambda fulfillment, and infrastructure components.


๐Ÿš€ Quick Start

Prerequisites

# Required tools
aws --version        # AWS CLI v2+
terraform --version  # Terraform v1.0+
node --version       # Node.js v16+

1. Deploy Infrastructure with Lambda

# Clone repository
git clone https://github.com/abaasi256/AWS-Health-Advice-Chatbot
cd aws-health-advice-chatbot

# Deploy AWS infrastructure with Lambda fulfillment
cd infra
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your preferences

terraform init
terraform plan
terraform apply

2. Setup Frontend with Voice

cd ../frontend
cp .env.example .env
# Update .env with Terraform output values

npm install
npm start
# Opens http://localhost:3000

3. Test Lambda Integration

  1. Test in AWS Console: Use TestBotAlias in Lex Console
  2. Test Frontend: Open http://localhost:3000
  3. Try Voice Features: Click microphone and speaker buttons
  4. Monitor Lambda: Check CloudWatch logs for function execution

๐Ÿ’ฌ Health Topics & Lambda Responses

The chatbot provides dynamic, AI-generated health advice through Lambda fulfillment:

Topic Voice Commands Lambda Response Features
๐Ÿฅ— Diet Tips "Give me healthy diet tips" Random selection from nutrition database + health disclaimer
๐Ÿ’ง Hydration "How much water should I drink?" Personalized hydration advice with intake calculations
๐Ÿƒโ€โ™€๏ธ Exercise "What exercises should I do?" Dynamic workout recommendations with intensity levels
๐Ÿง˜โ€โ™€๏ธ Mental Wellness "Give me mental wellness tips" Randomized mindfulness and stress management advice
๐Ÿ˜ด Sleep "How can I sleep better?" Sleep hygiene tips with personalized recommendations

Sample Lambda-Generated Response

๐Ÿ‘ค User: "I need mental wellness advice"

๐Ÿค– Lambda Response:
"Maintain strong social connections with family and friends. Keep a gratitude journal to focus on positive aspects of life.

โš ๏ธ Important: This is general health information for educational purposes only. Always consult with qualified healthcare providers for personalized medical guidance."

๐Ÿ”ง Lambda Integration Details

Lambda Function Architecture

  • Function Name: health-advice-chatbot-handler
  • Runtime: Python 3.9
  • Handler: healthAdviceHandler.lambda_handler
  • Timeout: 30 seconds
  • Memory: 128 MB

Health Advice Database

HEALTH_ADVICE = {
    'DietTips': [
        "Focus on whole foods like fruits, vegetables, lean proteins...",
        "Include healthy fats from sources like avocados, nuts...",
        "Eat the rainbow - different colored fruits and vegetables..."
    ],
    'ExerciseTips': [...],
    'MentalWellness': [...],
    'SleepAdvice': [...],
    'WaterInfo': [...]
}

Dynamic Response Generation

  • Random Selection: Varies advice on each interaction
  • Health Disclaimers: Automatically appended to all responses
  • Error Handling: Graceful fallbacks for unknown intents
  • Logging: CloudWatch integration for monitoring

๐ŸŽฏ Proof of Working Implementation

๐Ÿ—๏ธ Architecture Evidence

AWS Architecture Diagram Professional AWS architecture diagram using official AWS icons, showing the complete serverless infrastructure.

๐Ÿ“ธ Screenshot Evidence

1. AWS Lex Console - TestBotAlias Working

Lex Console Lambda integration successfully configured with TestBotAlias. Shows dynamic mental wellness advice generated by Lambda function.

2. Frontend Voice-Enabled Chat

Frontend Chat Complete voice-enabled frontend with working text-to-speech, speech recognition, and Lambda-generated responses with health disclaimers.

โœ… Verification Checklist

  • โœ… Lambda Function: health-advice-chatbot-handler deployed and working
  • โœ… Lex Integration: TestBotAlias configured with Lambda fulfillment
  • โœ… Dynamic Responses: Variable health advice generated per interaction
  • โœ… Voice Features: Full speech-to-text and text-to-speech functionality
  • โœ… Frontend Integration: React app successfully connects to Lex
  • โœ… Health Disclaimers: Automatically included in all Lambda responses
  • โœ… Error Handling: Graceful fallbacks and user-friendly error messages
  • โœ… Architecture Documentation: Professional AWS diagram with official icons

๐Ÿ› ๏ธ Technology Stack

Backend & Infrastructure

  • Amazon Lex v2 - Natural language understanding with intent recognition
  • AWS Lambda - Serverless compute for dynamic response generation
  • Python 3.9 - Lambda runtime with health advice logic
  • Terraform - Infrastructure as Code with Lambda deployment
  • CloudWatch - Logging and monitoring for Lambda functions
  • IAM - Fine-grained access control and Lambda permissions

Frontend & Voice

  • React 18 - Modern functional components with hooks
  • Web Speech API - Browser-native speech recognition and synthesis
  • AWS SDK v3 - Modular cloud service integration for Lex
  • Styled Components - CSS-in-JS with dynamic theming

Lambda Integration

  • Lex v2 Events - Proper event handling and response formatting
  • Dynamic Content - Randomized health advice selection
  • Error Handling - Robust exception management
  • Health Compliance - Medical disclaimers and educational focus

๐Ÿ“ Project Structure

aws-health-advice-chatbot/
โ”œโ”€โ”€ ๐Ÿ“‚ infra/                     # Terraform Infrastructure โญ
โ”‚   โ”œโ”€โ”€ main.tf                   # Lambda + Lex integration (WORKING)
โ”‚   โ”œโ”€โ”€ variables.tf               # Input variables
โ”‚   โ”œโ”€โ”€ outputs.tf                 # Infrastructure outputs
โ”‚   โ”œโ”€โ”€ terraform.tfvars.example   # Configuration template
โ”‚   โ””โ”€โ”€ lambda_function.zip        # Auto-generated Lambda package
โ”œโ”€โ”€ ๐Ÿ“‚ lambda/                     # Lambda Function โญ
โ”‚   โ”œโ”€โ”€ healthAdviceHandler.py     # Main Lambda handler (WORKING)
โ”‚   โ””โ”€โ”€ requirements.txt           # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“‚ frontend/                   # Voice-Enhanced React App โญ
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/            # UI components with voice
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ChatInterface.js   # Main chat with voice features
โ”‚   โ”‚   โ”œโ”€โ”€ services/              # AWS & Voice services
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ lexService.js      # AWS Lex integration
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ voiceService.js    # Voice capabilities (FIXED)
โ”‚   โ”‚   โ”œโ”€โ”€ config.js              # Voice configuration
โ”‚   โ”‚   โ””โ”€โ”€ App.js                 # Main application
โ”‚   โ”œโ”€โ”€ __tests__/                 # Voice feature tests
โ”‚   โ”œโ”€โ”€ package.json               # Dependencies with voice libs
โ”‚   โ””โ”€โ”€ README.md                  # Frontend voice guide
โ”œโ”€โ”€ ๐Ÿ“‚ Screenshots/                # Working Bot Evidence โญ
โ”‚   โ”œโ”€โ”€ aws-architecture-diagram.png          # Official AWS architecture diagram
โ”‚   โ”œโ”€โ”€ Screenshot 2025-05-26 at 9.39.04 PM.png  # Lex Console
โ”‚   โ””โ”€โ”€ Screenshot 2025-05-26 at 9.44.24 PM.png  # Frontend
โ””โ”€โ”€ ๐Ÿ“„ README.md                   # This documentation

โš™๏ธ Configuration

Infrastructure (infra/terraform.tfvars)

# Core Configuration
aws_region   = "us-east-1"
environment  = "dev"
project_name = "health-advice-chatbot"  
bot_name     = "HealthAdviceBot"
locale_id    = "en_US"

Voice Frontend (frontend/.env)

# AWS Lex Configuration (from Terraform outputs)
REACT_APP_AWS_REGION=us-east-1
REACT_APP_LEX_BOT_ID=your_bot_id_here
REACT_APP_LEX_LOCALE_ID=en_US

# Voice Configuration
REACT_APP_VOICE_ENABLED=true
REACT_APP_VOICE_AUTO_PLAY=true
REACT_APP_VOICE_SPEECH_RATE=1.0
REACT_APP_VOICE_SPEECH_PITCH=1.0
REACT_APP_VOICE_SPEECH_VOLUME=1.0
REACT_APP_VOICE_LANGUAGE=en-US

๐Ÿงช Testing

Lambda Function Testing

# Test Lambda locally
cd lambda
python3 healthAdviceHandler.py

# Expected output: JSON response with health advice

Voice Feature Testing

# Frontend Testing
cd frontend
npm test                    # Run all tests including voice
npm start                   # Test voice features manually

Integration Testing Checklist

โœ… Lambda function responds to Lex events
โœ… Voice toggle on/off works
โœ… Auto-play speaks bot responses  
โœ… Microphone captures speech correctly
โœ… Speech-to-text accuracy
โœ… Speaker icons appear on bot messages
โœ… Individual message playback works
โœ… TestBotAlias uses Lambda fulfillment
โœ… Dynamic responses vary between interactions
โœ… Health disclaimers included in all responses
โœ… CloudWatch logs show Lambda execution

Infrastructure Validation

cd infra
terraform validate
terraform plan
terraform fmt

๐Ÿ’ฐ Cost Analysis

Estimated Monthly Costs (Lambda + Voice Architecture)

Usage Level Lambda Lex v2 CloudWatch Voice APIs Total
Development $0.20 $1-2 $0.50 Free* ~$2.70
Light Production $0.60 $3-5 $1 Free* ~$6.60
Medium Production $2.00 $8-12 $2 Free* ~$14

*Voice APIs are browser-native and free

Lambda Cost Breakdown

  • Requests: $0.20 per 1M requests
  • Duration: $0.0000166667 per GB-second
  • Memory: 128 MB (cost-optimized)
  • Execution Time: ~100ms average

Cost Benefits of Lambda Architecture

  • Dynamic Responses: More engaging user experience
  • Scalable: Automatic scaling with usage
  • Educational Disclaimers: Proper health guidance compliance
  • Monitoring: Built-in CloudWatch logging
  • Maintainable: Easy to update health advice content

๐Ÿ”’ Security

Security Implementation

  • IAM Least Privilege - Separate roles for Lambda and Lex
  • Lambda Permissions - Specific ARN-based invocation permissions
  • No Data Storage - Stateless conversations, no PII retention
  • Voice Privacy - All voice processing happens locally in browser
  • Health Compliance - Educational disclaimers on all medical advice
  • Encryption - TLS 1.2+ for all data in transit
  • Monitoring - CloudWatch logging for Lambda execution and errors

Lambda Security

  • Execution Role - Minimal CloudWatch Logs permissions only
  • Source ARN - Restricted to specific Lex bot and alias
  • Environment Variables - Non-sensitive configuration only
  • Error Handling - No sensitive information in error messages

๐Ÿ“ˆ Monitoring & Observability

Application Metrics

  • Lambda function duration and memory usage
  • Lex conversation success rates
  • Intent recognition accuracy
  • User interaction patterns
  • Voice feature usage analytics

Lambda Monitoring

  • CloudWatch Logs: /aws/lambda/health-advice-chatbot-handler
  • Metrics: Invocations, Duration, Errors, Throttles
  • Alarms: Error rate and duration thresholds
  • X-Ray: Optional distributed tracing

Voice Analytics

  • Speech recognition success rates
  • Text-to-speech usage patterns
  • Voice vs text input preferences
  • Browser compatibility statistics

๐ŸŽฏ Professional Portfolio Value

Skills Demonstrated

  • โœ… AWS Cloud Architecture - Lex v2, Lambda, IAM, CloudWatch
  • โœ… Serverless Development - Python Lambda functions with proper error handling
  • โœ… Infrastructure as Code - Advanced Terraform patterns with Lambda deployment
  • โœ… Modern Frontend Development - React 18, hooks, state management
  • โœ… Voice Technology Integration - Web Speech API, audio processing
  • โœ… User Experience Design - Accessibility, mobile-first, voice UX
  • โœ… Performance Optimization - Cost-effective Lambda architecture
  • โœ… DevOps Practices - Automated deployment, testing, monitoring
  • โœ… Problem Solving - Complex integration challenges and solutions
  • โœ… Documentation Excellence - Professional diagrams and comprehensive guides

Innovation Highlights

  • Lambda-Powered Health Assistant - Dynamic, educational health advice
  • Voice-First Architecture - Complete speech integration with minimal cloud costs
  • Progressive Enhancement - Works perfectly with and without voice
  • Accessibility Excellence - Voice navigation for diverse user needs
  • Healthcare Compliance - Proper medical disclaimers and educational focus

๐Ÿ”ง Troubleshooting Lambda Integration

๐Ÿšจ Common Lambda Permission Issues

Issue 1: "Access denied while invoking lambda function" Error

Error Message:

Invalid Bot Configuration: Access denied while invoking lambda function 
arn:aws:lambda:us-east-1:ACCOUNT:function:health-advice-chatbot-handler 
from arn:aws:lex:us-east-1:ACCOUNT:bot-alias/BOTID/ALIASID. 
Please check the policy on this function.

Root Cause: Lambda function lacks permission for Lex bot alias to invoke it.

โœ… Solution:

  1. Add Bot Alias Lambda Permission:
# Get your bot ID and Lambda function name from Terraform outputs
BOT_ID=$(cd infra && terraform output -raw lex_bot_id)
LAMBDA_FUNCTION=$(cd infra && terraform output -raw lambda_function_name)
AWS_REGION=$(cd infra && terraform output -raw aws_region)
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)

# Add permission for bot alias to invoke Lambda
aws lambda add-permission \
  --function-name $LAMBDA_FUNCTION \
  --statement-id "AllowLexBotAlias" \
  --action "lambda:InvokeFunction" \
  --principal "lexv2.amazonaws.com" \
  --source-arn "arn:aws:lex:$AWS_REGION:$ACCOUNT_ID:bot-alias/$BOT_ID/*" \
  --region $AWS_REGION
  1. Verify Permission:
aws lambda get-policy --function-name $LAMBDA_FUNCTION --region $AWS_REGION

Issue 2: "Cannot call FulfillmentCodeHook" Error

Error Message:

Cannot call FulfillmentCodeHook for Intent ExerciseTips. 
BotAlias/LocaleId TestBotAlias/en_US doesn't have an associated Lambda Function.

Root Cause: Bot alias not properly configured with Lambda function association.

โœ… Solution - Create Bot Alias with Lambda Integration:

  1. Build Bot Locale:
BOT_ID=$(cd infra && terraform output -raw lex_bot_id)
LOCALE_ID=$(cd infra && terraform output -raw lex_bot_locale_id)
AWS_REGION=$(cd infra && terraform output -raw aws_region)

# Build the bot locale
aws lexv2-models build-bot-locale \
  --bot-id $BOT_ID \
  --bot-version "DRAFT" \
  --locale-id $LOCALE_ID \
  --region $AWS_REGION

# Wait for build to complete (check status)
aws lexv2-models describe-bot-locale \
  --bot-id $BOT_ID \
  --bot-version "DRAFT" \
  --locale-id $LOCALE_ID \
  --region $AWS_REGION \
  --query 'botLocaleStatus'
  1. Create Bot Version:
# Create bot version after locale is built
VERSION_RESPONSE=$(aws lexv2-models create-bot-version \
  --bot-id $BOT_ID \
  --description "Production version with Lambda" \
  --bot-version-locale-specification "$LOCALE_ID={sourceBotVersion=DRAFT}" \
  --region $AWS_REGION \
  --output json)

# Extract version number
BOT_VERSION=$(echo $VERSION_RESPONSE | jq -r '.botVersion')
echo "Created bot version: $BOT_VERSION"
  1. Create Bot Alias with Lambda Association:
LAMBDA_ARN=$(cd infra && terraform output -raw lambda_function_arn)

# Create alias with Lambda function
aws lexv2-models create-bot-alias \
  --bot-alias-name "TestBotAlias" \
  --description "Test alias with Lambda fulfillment" \
  --bot-version $BOT_VERSION \
  --bot-id $BOT_ID \
  --bot-alias-locale-settings "$LOCALE_ID={enabled=true,codeHookSpecification={lambdaCodeHook={lambdaArn=$LAMBDA_ARN,codeHookInterfaceVersion=1.0}}}" \
  --region $AWS_REGION
  1. Verify Alias Configuration:
# Get alias ID
ALIAS_ID=$(aws lexv2-models list-bot-aliases \
  --bot-id $BOT_ID \
  --region $AWS_REGION \
  --query 'botAliasSummaries[?botAliasName==`TestBotAlias`].botAliasId' \
  --output text)

# Check alias configuration
aws lexv2-models describe-bot-alias \
  --bot-id $BOT_ID \
  --bot-alias-id $ALIAS_ID \
  --region $AWS_REGION

๐Ÿ› ๏ธ Complete Lambda Permission Fix Script

Create this script to fix both issues automatically:

#!/bin/bash
# fix-lambda-permissions.sh

set -e

echo "๐Ÿ”ง Fixing Lambda permissions for Lex bot..."

# Get Terraform outputs
cd infra
BOT_ID=$(terraform output -raw lex_bot_id)
BOT_NAME=$(terraform output -raw lex_bot_name)
LAMBDA_FUNCTION=$(terraform output -raw lambda_function_name)
LAMBDA_ARN=$(terraform output -raw lambda_function_arn)
LOCALE_ID=$(terraform output -raw lex_bot_locale_id)
AWS_REGION=$(terraform output -raw aws_region)
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
cd ..

echo "๐Ÿ“‹ Configuration:"
echo "  Bot ID: $BOT_ID"
echo "  Lambda: $LAMBDA_FUNCTION"
echo "  Region: $AWS_REGION"

# Step 1: Add Lambda permissions
echo "๐Ÿ” Adding Lambda permissions..."

# Permission for bot
aws lambda add-permission \
  --function-name $LAMBDA_FUNCTION \
  --statement-id "AllowLexBot" \
  --action "lambda:InvokeFunction" \
  --principal "lexv2.amazonaws.com" \
  --source-arn "arn:aws:lex:$AWS_REGION:$ACCOUNT_ID:bot/$BOT_ID/*" \
  --region $AWS_REGION || echo "Bot permission already exists"

# Permission for bot alias
aws lambda add-permission \
  --function-name $LAMBDA_FUNCTION \
  --statement-id "AllowLexBotAlias" \
  --action "lambda:InvokeFunction" \
  --principal "lexv2.amazonaws.com" \
  --source-arn "arn:aws:lex:$AWS_REGION:$ACCOUNT_ID:bot-alias/$BOT_ID/*" \
  --region $AWS_REGION || echo "Bot alias permission already exists"

echo "โœ… Lambda permissions configured"

# Step 2: Build bot locale
echo "๐Ÿ”จ Building bot locale..."
aws lexv2-models build-bot-locale \
  --bot-id $BOT_ID \
  --bot-version "DRAFT" \
  --locale-id $LOCALE_ID \
  --region $AWS_REGION

# Wait for build
echo "โณ Waiting for bot locale build..."
while true; do
  STATUS=$(aws lexv2-models describe-bot-locale \
    --bot-id $BOT_ID \
    --bot-version "DRAFT" \
    --locale-id $LOCALE_ID \
    --region $AWS_REGION \
    --query 'botLocaleStatus' \
    --output text)
  
  echo "  Build status: $STATUS"
  
  if [ "$STATUS" = "Built" ]; then
    break
  elif [ "$STATUS" = "Failed" ]; then
    echo "โŒ Bot locale build failed"
    exit 1
  fi
  
  sleep 10
done

echo "โœ… Bot locale built successfully"

# Step 3: Create bot version
echo "๐Ÿ“ฆ Creating bot version..."
VERSION_RESPONSE=$(aws lexv2-models create-bot-version \
  --bot-id $BOT_ID \
  --description "Version with Lambda fulfillment" \
  --bot-version-locale-specification "$LOCALE_ID={sourceBotVersion=DRAFT}" \
  --region $AWS_REGION \
  --output json)

BOT_VERSION=$(echo $VERSION_RESPONSE | jq -r '.botVersion')
echo "โœ… Created bot version: $BOT_VERSION"

# Wait for version
echo "โณ Waiting for bot version..."
while true; do
  STATUS=$(aws lexv2-models describe-bot-version \
    --bot-id $BOT_ID \
    --bot-version $BOT_VERSION \
    --region $AWS_REGION \
    --query 'botStatus' \
    --output text)
  
  echo "  Version status: $STATUS"
  
  if [ "$STATUS" = "Available" ]; then
    break
  elif [ "$STATUS" = "Failed" ]; then
    echo "โŒ Bot version creation failed"
    exit 1
  fi
  
  sleep 5
done

# Step 4: Create/update bot alias with Lambda
echo "๐Ÿ”— Creating bot alias with Lambda association..."

# Delete existing alias if it exists
aws lexv2-models delete-bot-alias \
  --bot-id $BOT_ID \
  --bot-alias-id TSTALIASID \
  --region $AWS_REGION 2>/dev/null || echo "No existing alias to delete"

# Create new alias
aws lexv2-models create-bot-alias \
  --bot-alias-name "TestBotAlias" \
  --description "Test alias with Lambda fulfillment" \
  --bot-version $BOT_VERSION \
  --bot-id $BOT_ID \
  --bot-alias-locale-settings "$LOCALE_ID={enabled=true,codeHookSpecification={lambdaCodeHook={lambdaArn=$LAMBDA_ARN,codeHookInterfaceVersion=1.0}}}" \
  --region $AWS_REGION

echo "๐ŸŽ‰ Lambda integration fixed!"
echo ""
echo "โœ… Next steps:"
echo "  1. Test in Lex console with TestBotAlias"
echo "  2. Try: 'Give me healthy diet tips'"
echo "  3. Check CloudWatch logs: /aws/lambda/$LAMBDA_FUNCTION"
echo "  4. Update frontend .env if needed"

Usage:

chmod +x fix-lambda-permissions.sh
./fix-lambda-permissions.sh

๐Ÿงช Testing Lambda Integration

Test in AWS Console:

  1. Go to Lex Console
  2. Open your HealthAdviceBot
  3. Use TestBotAlias for testing
  4. Try: "Give me healthy diet tips"
  5. Verify Lambda function is called in CloudWatch logs

Test via CLI:

# Test bot alias directly
aws lexv2-runtime recognize-text \
  --bot-id $BOT_ID \
  --bot-alias-id "TSTALIASID" \
  --locale-id $LOCALE_ID \
  --session-id "test-session" \
  --text "Give me healthy diet tips" \
  --region $AWS_REGION

Monitor Lambda Execution:

# Watch Lambda logs in real-time
aws logs tail /aws/lambda/health-advice-chatbot-handler --follow --region $AWS_REGION

๐Ÿ” Verification Checklist

Lambda Permissions:

  • Bot-level permission exists
  • Bot-alias level permission exists
  • Lambda policy shows both permissions

Bot Configuration:

  • Bot locale is "Built" status
  • Bot version is "Available"
  • Bot alias exists with Lambda ARN
  • TestBotAlias shows Lambda configuration

Testing:

  • Lex console test works with TestBotAlias
  • Lambda function executes (check CloudWatch)
  • Dynamic responses vary between tests
  • Health disclaimers appear in responses
  • Frontend connects to bot alias

Common Issues:

  • ๐Ÿšซ "No alias found" โ†’ Run alias creation step
  • ๐Ÿšซ "Access denied" โ†’ Add Lambda permissions
  • ๐Ÿšซ "Bot not found" โ†’ Check Terraform deployment
  • ๐Ÿšซ "Function timeout" โ†’ Check Lambda logs

๐Ÿ†˜ Emergency Reset

If everything breaks:

# 1. Destroy and recreate infrastructure
cd infra
terraform destroy -auto-approve
terraform apply -auto-approve

# 2. Run fix script
cd ..
./fix-lambda-permissions.sh

# 3. Test immediately
echo "Testing bot alias..."
BOT_ID=$(cd infra && terraform output -raw lex_bot_id)
aws lexv2-runtime recognize-text \
  --bot-id $BOT_ID \
  --bot-alias-id "TSTALIASID" \
  --locale-id "en_US" \
  --session-id "emergency-test" \
  --text "Give me diet tips" \
  --region us-east-1

Result: Complete Lambda integration with proper permissions and bot alias configuration.


๐Ÿ”ง Development & Customization

Adding New Health Topics

  1. Update Lambda Function (lambda/healthAdviceHandler.py):
HEALTH_ADVICE = {
    'NewHealthTopic': [
        "Your new health advice content here...",
        "Additional advice for variety...",
        "More educational content..."
    ]
}
  1. Add Intent to Terraform (infra/main.tf):
resource "aws_lexv2models_intent" "new_health_topic" {
  bot_id      = aws_lexv2models_bot.health_advice_bot.id
  bot_version = "DRAFT"
  locale_id   = aws_lexv2models_bot_locale.health_advice_bot_locale.locale_id
  name        = "NewHealthTopic"

  sample_utterance {
    utterance = "Tell me about new health topic"
  }

  fulfillment_code_hook {
    enabled = true
  }
}
  1. Deploy Changes:
cd infra
terraform apply
  1. Test with voice commands and Lambda responses

Voice Customization

// Customize voice settings in config.js
voice: {
  enabled: true,
  autoPlay: true,
  speechRate: 1.2,      // Faster speech
  speechPitch: 1.1,     // Higher pitch
  speechVolume: 0.9,    // Slightly quieter
  language: 'en-US'
}

๐Ÿ† Architecture Decision: Lambda + Voice Integration

Why This Architecture?

  • โœ… Dynamic Content Generation - Varied responses prevent repetition
  • โœ… Educational Compliance - Automatic health disclaimers
  • โœ… Superior User Experience - Voice + intelligent responses
  • โœ… Scalable Architecture - Lambda scales automatically with usage
  • โœ… Cost Effective - Pay-per-use Lambda model
  • โœ… Maintainable - Easy to update health advice content
  • โœ… Monitorable - Built-in CloudWatch logging and metrics

Technical Innovation

  • Browser-Native Voice - No cloud audio processing required
  • Lambda Fulfillment - Dynamic health advice generation
  • Local Privacy - All voice processing happens on user's device
  • Progressive Enhancement - Graceful fallback for any browser

Result: A production-ready, voice-enabled health assistant that demonstrates cutting-edge serverless and frontend skills while maintaining optimal cloud architecture and user experience.


๐Ÿ”ฎ Future Enhancements

Lambda Roadmap

  • ๐Ÿ” Personalization - User context and preference tracking
  • ๐Ÿ“Š Analytics - Health advice effectiveness metrics
  • ๐ŸŒ Multi-Language - Internationalization support
  • ๐Ÿ”— Integration - External health APIs and databases

Voice Roadmap

  • ๐ŸŽต Voice Personalities - Multiple voice options and tones
  • ๐ŸŒ Multi-Language Voice - Support for Spanish, French, German
  • ๐Ÿ‘‚ Wake Words - "Hey Health Assistant" activation
  • ๐Ÿ—ฃ๏ธ Conversation Memory - Context-aware voice interactions

Technical Roadmap

  • AWS Polly Integration - Professional voice quality option
  • Lambda Layers - Shared health advice libraries
  • Step Functions - Complex health advice workflows
  • API Gateway - RESTful health advice endpoints

๐Ÿค Contributing

This is a portfolio project demonstrating modern cloud and voice development skills. For feedback or collaboration:

  1. Fork the repository
  2. Create a feature branch
  3. Implement Lambda or voice improvements
  4. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ† Portfolio Contact

Ready to discuss this Lambda-powered, voice-enabled cloud solution?


โญ Star this repository if it demonstrates the modern serverless and voice technology skills you're looking for!

๐ŸŽคโšก Built with โค๏ธ to showcase cutting-edge AWS Lambda integration and voice technology

Try the voice features live - ask about your health and listen to the intelligent Lambda-generated responses!

๐ŸŽฏ Lambda Function: health-advice-chatbot-handler | ๐Ÿค– Bot Alias: TestBotAlias | ๐ŸŽค Voice: Enabled

About

๐Ÿฅ Production-ready AWS Health Advice Chatbot with Lambda fulfillment, Lex v2 NLU, and full voice integration. Features dynamic health advice generation, speech-to-text/text-to-speech capabilities, and Infrastructure as Code deployment. Built with React, Python Lambda, and Terraform.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published