Skip to content

Voice-controlled AI assistant using Alexa Skills Kit, Spring Boot backend, and AWS Bedrock (Claude 3 Haiku)

Notifications You must be signed in to change notification settings

lensoncode/alexa-ai-assistant-bedrock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Alexa AI Assistant with AWS Bedrock

A complete Alexa skill that integrates with AWS Bedrock (Claude 3 Haiku) through a Spring Boot backend deployed on Elastic Beanstalk.

๐ŸŽ“ Learning Project: This entire project was created using Cursor IDE and AWS Bedrock to explore modern AI-powered development tools. Every line of code, configuration, test, and documentation was generated with AI assistance through Cursor, demonstrating the power of AI-driven development while learning AWS Bedrock integration patterns.

๐ŸŽฏ What This Project Does

  • Voice Interaction: Ask questions through any Alexa device
  • AI Processing: Powered by Claude 3 Haiku via AWS Bedrock
  • Scalable Backend: Spring Boot on Elastic Beanstalk
  • Cost Protection: Automatic service cutoff to prevent unexpected bills
  • Security: API key authentication between components
  • Enterprise Testing: Comprehensive test suite with CI/CD pipeline

๐Ÿ—๏ธ System Architecture

The following diagram shows the complete end-to-end flow from voice command to AI response:

graph TB
    subgraph "User Interaction"
        A[๐Ÿ—ฃ๏ธ Alexa Device] --> B["Voice: 'Alexa, ask my ai what is Database?'"]
    end
    
    subgraph "AWS Lambda Layer"
        B --> C[๐Ÿ”ต Alexa Skill Lambda Function]
        C --> |"HTTP POST + API Key"| D[Backend Request]
        D --> |"JSON: {message: 'what is Database'}"| E[Spring Boot Backend]
    end
    
    subgraph "Elastic Beanstalk Environment"
        E[๐ŸŒ Spring Boot Backend<br/>Port 5000<br/>Corretto 17] --> F[API Key Validation]
        F --> |"Valid Key"| G[Input Validation]
        F --> |"Invalid Key"| H[โŒ 401 Unauthorized]
        G --> |"Valid Input"| I[Bedrock API Call]
        G --> |"Invalid Input"| J[โŒ 400 Bad Request]
    end
    
    subgraph "AWS Bedrock"
        I --> K[๐Ÿค– Claude 3 Haiku<br/>anthropic.claude-3-haiku-20240307-v1:0]
        K --> L["AI Response:<br/>'A database is a structured collection<br/>of data stored electronically...'"]
    end
    
    subgraph "Response Flow"
        L --> M[JSON Response]
        M --> |"HTTP 200"| N[Lambda Processing]
        N --> O[Alexa Response]
        O --> P[๐Ÿ—ฃ๏ธ Voice Output to User]
    end
    
    subgraph "Cost Protection System"
        Q[๐Ÿ’ฐ CloudWatch Alarms<br/>$10, $25, $40 thresholds] --> R[๐Ÿ“ง SNS Notifications<br/>Email Alerts]
        R --> |"$40 Threshold"| S[๐Ÿšจ Budget Cutoff Lambda<br/>Auto-terminate services]
        S --> T[๐Ÿ›‘ Service Shutdown<br/>EB Environment + Lambda]
    end
    
    subgraph "Security & Configuration"
        U[๐Ÿ” API Key Authentication<br/>Alexa โ†” Backend] 
        V[๐ŸŒ Environment Variables<br/>AWS_REGION, BEDROCK_MODEL_ID]
        W[โš™๏ธ IAM Roles<br/>EC2 โ†’ Bedrock permissions]
    end
    
    subgraph "Development & Testing"
        X[๐Ÿงช Comprehensive Test Suite<br/>Unit + Integration + E2E]
        Y[๐Ÿš€ CI/CD Pipeline<br/>GitHub Actions]
        Z[๐Ÿ“Š Monitoring<br/>CloudWatch + Health Checks]
    end
    
    style A fill:#e1f5fe
    style C fill:#f3e5f5
    style E fill:#e8f5e8
    style K fill:#fff3e0
    style Q fill:#ffebee
    style U fill:#f1f8e9
    style X fill:#e3f2fd
Loading

Architecture Components

Component Technology Purpose
Alexa Device Amazon Echo/Dot Voice interface for user interaction
Alexa Skill Node.js Lambda Processes voice commands and responses
Backend API Spring Boot Handles business logic and Bedrock integration
AI Engine AWS Bedrock (Claude 3 Haiku) Generates intelligent responses
Infrastructure Elastic Beanstalk Scalable hosting for backend service
Cost Protection CloudWatch + Lambda Automatic cost control and service cutoff
Security API Keys + IAM Authentication and authorization
Testing JUnit + Mocha + Integration Comprehensive quality assurance

๐Ÿš€ Quick Start

Prerequisites

  • AWS Account with appropriate permissions
  • AWS CLI configured
  • Java 17+, Maven 3.6+, Node.js 18+
  • EB CLI installed

1. Clone and Setup

git clone <your-repo>
cd alexa-chatgpt-java

# Install prerequisites
./install-prerequisites.sh

# Automated setup (recommended)
./setup-environment.sh

# OR Manual setup
cp environment-variables.template .env
cp alexa-skill-nodejs/lambda-env.template alexa-skill-nodejs/.env
cp java-backend-springboot/.ebextensions/01-port.config.template java-backend-springboot/.ebextensions/01-port.config
# Edit the files above with your specific AWS account details

2. Deploy Backend

cd java-backend-springboot
eb init    # Choose your region and platform
eb create  # Create environment
eb deploy  # Deploy application

3. Deploy Alexa Skill

cd alexa-skill-nodejs
npm install
./deploy-lambda.sh  # Follow the script instructions

4. Configure Alexa Developer Console

  1. Go to Alexa Developer Console
  2. Create new skill using skill-package/skill.json
  3. Update Lambda ARN with your function ARN
  4. Test and publish

๐Ÿ’ฐ Cost Protection

Includes comprehensive cost protection:

  • $10 Threshold: Early warning email
  • $25 Threshold: Budget alert email
  • $40 Threshold: Automatic service termination

Deploy cost protection:

# Update budget-cutoff-lambda.py with your service names
./deploy-cost-protection.sh

๐Ÿ”ง Configuration

Environment Variables Required

  • AWS_REGION: Your AWS region (e.g., eu-central-1)
  • AWS_ACCOUNT_ID: Your 12-digit AWS account ID
  • ALEXA_API_KEY: Generated API key for authentication
  • BACKEND_HOST: Your Elastic Beanstalk URL
  • BEDROCK_MODEL_ID: anthropic.claude-3-haiku-20240307-v1:0

Template Files

  • environment-variables.template โ†’ Copy to .env
  • alexa-skill-nodejs/lambda-env.template โ†’ Copy to alexa-skill-nodejs/.env
  • java-backend-springboot/.ebextensions/01-port.config.template โ†’ Copy and configure

๐Ÿงช Testing

Test Backend API

curl -X POST http://YOUR_EB_URL/chat \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{"message": "Hello, what is AI?"}'

Test Alexa Skill

"Alexa, ask my ai what is artificial intelligence?"

๐Ÿ“Š Expected Costs

  • Elastic Beanstalk (t3.micro): ~$8-15/month
  • Lambda: ~$0.50/month (1000 requests)
  • Bedrock (Claude 3 Haiku): ~$0.25 per 1M tokens
  • Total: ~$10-20/month for moderate usage

๐Ÿ”’ Security Features

  • API key authentication between Alexa and backend
  • IAM roles with minimal required permissions
  • Input validation and sanitization
  • VPC deployment ready (optional)

๐Ÿ“š Documentation

  • SETUP.md - Detailed setup instructions
  • SECURITY.md - Security considerations
  • COST_OPTIMIZATION.md - Cost optimization strategies
  • TESTING_GUIDE.md - Comprehensive testing guide
  • AWS_USER_PERMISSIONS.md - Required AWS permissions

๐Ÿ†˜ Troubleshooting

Common Issues

Issue Solution
EB CLI not found brew install aws-elasticbeanstalk
Bedrock access denied Request access in AWS Console
Lambda timeout Increase timeout in configuration
API key errors Check environment variables

Useful Commands

# Check deployment status
eb status
eb logs

# Test Lambda function
aws lambda invoke --function-name YOUR_FUNCTION_NAME test-output.json

# Monitor costs
aws budgets describe-budgets --account-id YOUR_ACCOUNT_ID

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

โš ๏ธ Important Security Notes

  • Never commit sensitive information (API keys, account IDs, emails)
  • Always use environment variables for configuration
  • Test in development before deploying to production
  • Monitor costs regularly using AWS Cost Explorer
  • Keep dependencies updated for security patches

๐Ÿ“„ License

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

๐ŸŽ‰ Features

  • โœ… Voice-activated AI assistant
  • โœ… AWS Bedrock integration (Claude 3 Haiku)
  • โœ… Scalable Spring Boot backend
  • โœ… Automatic cost protection
  • โœ… Security with API keys
  • โœ… Comprehensive monitoring
  • โœ… Easy deployment scripts
  • โœ… Production-ready configuration

๐Ÿ”ฎ Future Enhancements

  • Multi-turn conversations with context
  • Different AI models based on query complexity
  • Web interface for testing
  • Integration with other voice assistants
  • Advanced analytics and usage tracking

๐ŸŽ“ Learning Journey: Cursor IDE + AWS Bedrock

This project represents a comprehensive exploration of modern AI-powered development tools and cloud services:

๐Ÿ–ฑ๏ธ Cursor IDE Experience

This entire codebase was built using Cursor IDE, showcasing its capabilities for:

  • ๐Ÿค– AI-Assisted Development: Leveraged Cursor's AI features for code generation, debugging, and optimization
  • ๐Ÿง  Intelligent Code Completion: Used AI suggestions for complex AWS integrations and Spring Boot configurations
  • ๐Ÿ” Context-Aware Assistance: Benefited from Cursor's understanding of the project structure for consistent code patterns
  • โšก Rapid Prototyping: Accelerated development through AI-powered code generation and refactoring
  • ๐Ÿ› Smart Debugging: Utilized AI assistance for troubleshooting deployment issues and configuration problems
  • ๐Ÿ“š Documentation Generation: Leveraged AI for creating comprehensive documentation and README content

๐Ÿง  AWS Bedrock Integration Learning

The project served as a hands-on exploration of AWS Bedrock capabilities:

  • ๐Ÿค Claude 3 Haiku Integration: Implemented direct API calls to Anthropic's Claude model through Bedrock
  • ๐Ÿ”ง SDK Configuration: Learned AWS SDK setup and configuration for Bedrock services
  • ๐ŸŒ Regional Deployment: Configured services in eu-central-1 region for optimal performance
  • ๐Ÿ’ฐ Cost Management: Implemented comprehensive cost controls and monitoring for Bedrock usage
  • ๐Ÿ” Security Best Practices: Applied proper IAM roles and API key management for Bedrock access
  • โšก Performance Optimization: Optimized request patterns and response handling for Claude interactions

๐Ÿ“ˆ Skills and Technologies Mastered

Through this learning project, the following technologies were explored:

Category Technologies Learned
AI Development Cursor IDE, AWS Bedrock, Claude 3 Haiku API
Backend Development Spring Boot, Java 17, Maven, REST APIs
Cloud Infrastructure AWS Elastic Beanstalk, Lambda, CloudWatch, SNS
Voice Technology Amazon Alexa Skills Kit, Voice User Interface design
DevOps & Testing GitHub Actions, JUnit, Integration testing, CI/CD
Security API key management, IAM roles, Cost protection
Monitoring CloudWatch alarms, SNS notifications, Health checks

๐ŸŽฏ Key Learning Outcomes

  1. ๐Ÿš€ Modern IDE Capabilities: Experienced the power of AI-assisted development with Cursor
  2. โ˜๏ธ Cloud-Native Architecture: Built a production-ready, scalable cloud application
  3. ๐Ÿค– AI Service Integration: Successfully integrated enterprise AI services (Bedrock) into applications
  4. ๐Ÿ—ฃ๏ธ Voice Interface Development: Created a functional voice-activated AI assistant
  5. ๐Ÿ”’ Security-First Approach: Implemented comprehensive security and cost controls
  6. ๐Ÿงช Test-Driven Development: Built enterprise-grade testing and CI/CD pipelines
  7. ๐Ÿ“Š Production Monitoring: Set up comprehensive monitoring and alerting systems

๐Ÿ’ก Development Insights

What Worked Well:

  • Cursor's AI assistance accelerated development by ~3-4x
  • AWS Bedrock provided reliable, high-quality AI responses
  • Spring Boot offered excellent AWS SDK integration
  • Comprehensive testing prevented deployment issues

Challenges Overcome:

  • Complex AWS IAM permission configurations
  • Alexa skill deployment and testing workflows
  • Cost management and automatic service cutoffs
  • Multi-service integration and error handling

Best Practices Discovered:

  • Environment variable management for multi-service applications
  • API key rotation and security patterns
  • Cost monitoring and automatic protection mechanisms
  • Comprehensive testing strategies for cloud applications

๐ŸŒŸ Project Impact

This learning project demonstrates:

  • Production-Ready Code: Enterprise-grade application with full testing and CI/CD
  • Modern Development Practices: AI-assisted development with proper DevOps workflows
  • Cloud-Native Design: Scalable, secure, and cost-effective cloud architecture
  • Real-World Application: Functional voice assistant that actually works on physical Alexa devices

Perfect example of how modern AI development tools can accelerate learning and building complex, production-ready applications! ๐ŸŽ‰


Ready to deploy your own AI-powered Alexa skill? Follow the setup guide and start building! ๐Ÿš€

About

Voice-controlled AI assistant using Alexa Skills Kit, Spring Boot backend, and AWS Bedrock (Claude 3 Haiku)

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published