A scalable, serverless chatbot pipeline built using AWS services and React.js to analyze and optimize cloud resource usage based on user queries. The system captures user input, interprets it using Amazon Lex, invokes relevant Lambda workflows, and leverages Amazon SageMaker for predictive analytics, returning results via DynamoDB.
- Serverless Architecture: Cost-effective, on-demand usage without maintaining servers
- Natural Language Processing: Amazon Lex for understanding user queries
- Real-time Recommendations: EC2 instance rightsizing suggestions via SageMaker
- Asynchronous Processing: Query handling through Amazon SQS and Step Functions
- Scalable Data Management: Efficient processing using Lambda and DynamoDB
- Request Tracking: Query status tracking using unique request/session IDs
The chatbot follows a sophisticated serverless architecture pattern:
- User submits query through React frontend
- API Gateway routes request to Lambda
- Lambda forwards to Amazon Lex for intent recognition
- Structured data flows to SQS for asynchronous processing
- Step Functions orchestrate analysis workflows
- SageMaker provides predictive insights
- Results stored in DynamoDB for retrieval
- React.js
- HTML, CSS, JavaScript
- AWS Lambda
- Amazon API Gateway
- Amazon Lex v2
- Amazon SQS
- Amazon SageMaker
- Amazon CloudWatch
- AWS Cost Explorer
- AWS Step Functions
- Amazon S3
- Amazon DynamoDB
- Python (Boto3, Regex)
- Postman (for testing APIs)
- Git & GitHub
The chatbot interface was built using React.js to enable a clean and interactive frontend for querying AWS resource usage.
- App.js: Main component that handles user interaction and sends requests
- index.js: Application entry point
- App.css, index.css: Stylesheets for component and global styling
- reportWebVitals.js: Performance monitoring (optional)
- setupTests.js, App.test.js: Set up and define component testing
- Clean UI to interact with the Amazon Lex chatbot
- Users can type natural language queries like:
- "Check my EC2 usage from Jan 1 to Jan 15"
- "Is my instance i-08fabc123xyz underutilized?"
- The frontend sends queries to API Gateway, which forwards them to Lambda for Lex processing
- Slots: service_name, from_date, to_date
- Example Query: "Check my EC2 usage from 2024-01-01 to 2024-02-01"
- Features: Date parsing (via custom slot + regex) and service identification
- Slots: instance_id
- Example Query: "Is my EC2 instance i-123abc oversized?"
- Triggered by API Gateway
- Receives user input, forwards it to Amazon Lex using recognizeText()
- Fulfillment Lambda connected to Lex
- Extracts intent and slot values
- Formats message and pushes to Amazon SQS for asynchronous processing
- Triggered by SQS events
- Starts a Step Function execution using the received message to orchestrate downstream ML/data tasks
- Fetches historical usage data from AWS CloudWatch and Cost Explorer
- Aggregates and analyzes metrics for services like S3, Lambda, RDS, etc.
- Formats and stores the result in DynamoDB with cost and utilization summary
- Retrieves EC2 metrics from CloudWatch and other sources
- Sends data to a deployed Random Forest model on SageMaker
- Generates instance type recommendations and stores them in DynamoDB
- Triggered via API GET request
- Queries DynamoDB using session ID to retrieve processed results for the user
- Input: JSON-formatted vector of historical EC2 usage metrics (e.g., CPUUtilization, Network I/O, Disk Ops) associated with an instance_id
- Model: Trained Random Forest classifier designed to evaluate resource utilization patterns and classify instance efficiency
- Output: Label indicating whether the instance is Underutilized, Overutilized, or Right-Sized, enabling actionable rightsizing recommendations
Here are some example interactions with the chatbot:
// Example 1: SQS Message Processing
Input: "Check my SQS queue metrics"
Output: "Service: SQS, Cost: 0.00 USD, Utilization Summary: SentMessageSize: 968.7351190476619, NumberOfMessagesSent: 0.11980669014747812, ApproximateNumberOfMessagesDelayed: 0.0"
// Example 2: Lambda Function Analysis
Input: "Can you get my Lambda usage from 2025-04-01 to 2025-04-15?"
Output: "Service: Lambda, Cost: 0.00 USD, Utilization Summary: Errors: 0.0, ConcurrentExecutions: 3.0, Duration: 2812.865"
// Example 3: EC2 Instance Optimization
Input: "Is my EC2 instance i-0efd4ce1cbdccabb0 right-sized?"
Output: "Scale down to a smaller instance to reduce costs. Suggested type: t2.xlarge"# Install dependencies
npm install
# Start the development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run previewYou can interact with the chatbot in two ways:
Simply type your message in the chat interface. For example:
Check my EC2 usage from 2025-01-01 to 2025-04-04
Headers:
Content-Type: application/json
Request Body:
{
"message": "Check my EC2 usage from 2025-01-01 to 2025-04-04"
}Response:
{
"type": "bot",
"content": "Processing your request...",
"timestamp": "2025-03-20T10:30:00Z"
}- Real-Time Notifications: Integrate Amazon SNS to alert users once processing is complete, enhancing responsiveness and engagement
- Multi-Service Reporting: Enable support for comparing and reporting usage across multiple AWS services in a single query
- Expand ML Model Capabilities: Extend the SageMaker model to support additional AWS services and multi-metric analysis for more precise rightsizing and cost-optimization recommendations

