🚀 AWS Project: AWS Serverless Sentiment Analysis
A lightweight, serverless web application for performing sentiment analysis on user-provided text using AWS Comprehend. The backend logic is handled by AWS Lambda and is accessible through Amazon API Gateway. A simple frontend interface allows users to submit text, which is then processed to determine its sentiment (e.g., Positive, Negative, Neutral, Mixed).
This project utilizes the following AWS services:
- AWS Lambda for serverless compute
- Amazon API Gateway to expose the API
- Amazon S3 for hosting the frontend (if applicable)
- Amazon Comprehend for natural language processing and sentiment detection
The application is designed to be cost-effective, scalable, and easy to deploy, following a fully serverless architecture.
- 🔍 Analyze text sentiment (Positive, Negative, Neutral, Mixed)
- ⚡ Fast response
- 🌐 Exposed via AWS API Gateway
- 🖥️ Simple frontend for user input
- ☁️ 100% serverless on AWS
- AWS Root Account
- AWS Lambda — Python-based serverless function using the Boto3 SDK
- Amazon Comprehend — Sentiment Detection Service
- Amazon API Gateway — REST API to expose Lambda function
- Amazon S3 — Hosting static frontend (HTML, JS)
- AWS IAM — Roles and policies for secure access management
- Postman — API testing tool for verifying endpoints
-
Create an S3 bucket and upload the
index.html
file. -
Enable Static Website Hosting under the bucket's Properties tab.
-
Set the ACL permissions to public to allow public access to the files.
-
Create a Lambda Function named
SentimentAnalysisFunction
. -
Upload the
lambda_function.py
file as the function code. -
Use Boto3 SDK within Lambda to invoke AWS Comprehend.
-
Deploy the function and test to ensure it returns a successful status (
200 OK
). -
Configure Lambda with:
- Memory: 1280 MB
- Timeout: 1 minute 3 seconds
Attach the following IAM policies to the Lambda execution role:
Policy Name | Type |
---|---|
AmazonAPIGatewayAdministrator | AWS Managed |
AmazonAPIGatewayInvokeFullAccess | AWS Managed |
AmazonS3FullAccess | AWS Managed |
AWSLambdaBasicExecutionRole-a9e941ff... | Customer Managed |
ComprehendFullAccess | AWS Managed |
sentiment-analysis-results-policy | Customer Inline |
- View the inline policy:
sentiment-analysis-results-policy.json
IAM Permissions Configuration:
- Method: POST
- Resource:
/analyze
- Integration Type: Lambda Proxy Integration
- CORS: Enabled (
*
)
API Gateway Setup Screenshots:
-
502 Internal Server Error
Ensure that the Lambda function correctly parses the incoming request usingevent['body']
. Incorrect parsing may lead to malformed responses and trigger this error. -
CORS Errors in Browser
Confirm that CORS (Cross-Origin Resource Sharing) is enabled in your API Gateway configuration. Allow the required headers and methods (typically*
for development). -
AWS Lambda Permission Issues
Make sure that the ComprehendFullAccess policy is attached to the IAM role associated with your Lambda function. Without this, AWS Comprehend cannot be invoked from Lambda. -
Missing Static Website URL (S3)
Verify that Static Website Hosting is enabled in the S3 bucket properties. Also ensure that the index document is set (e.g.,index.html
) and that public read permissions are applied. -
Frontend Fetch API Errors (Network Error)
Confirm that you are using the correct API Gateway Invoke URL in your frontend JavaScript. Any mismatch (like using a wrong stage URL) will lead to fetch/network failures. -
Lambda Timeout Exceeded
If Lambda runs longer than expected and times out, increase the timeout limit in Lambda settings (under Configuration → General Configuration). -
Access Denied (403) Errors in S3
Ensure that ACL permissions are set to public or the correct bucket policy is in place to allow public access to your static files. -
API Gateway Deployment Not Updated
After making changes in API Gateway (like enabling CORS or changing integrations), don’t forget to Deploy the API to the selected stage. Otherwise, your changes won't take effect. -
Boto3 Module Not Found in Lambda
AWS Lambda comes with boto3 pre-installed. If you're deploying a custom package or layer, ensure it doesn't conflict or miss the boto3 library. -
Invalid JSON Format in API Requests
Make sure that the request body sent via the frontend or Postman is valid JSON format. Example:{ "text": "Your sample text here" }
Indana Aditya LinkedIn • GitHub