SENTIMENT ANALYSIS USING AWS SNS AND AWS COMPREHEND (not at free of cost)
Автор: The Cloud Diaries
Загружено: 2025-03-20
Просмотров: 125
Описание:
In this video, we explore how to perform Sentiment Analysis using AWS Comprehend and trigger notifications with AWS SNS. Learn how to analyze text sentiment (positive, negative, neutral, or mixed) and automate alerts based on the results. Perfect for AI-driven customer feedback analysis, social media monitoring, and more! 🚀
🔹 What You’ll Learn:
✅ Introduction to AWS Comprehend & SNS
✅ Setting up sentiment analysis in AWS
✅ Automating alerts with SNS
✅ Hands-on demo with real-world use cases
Also they charge me 0.65 dollar for sms notifications..
Don't forget to like, share, and subscribe for more cloud and AI tutorials! 🔥💡
ESSENTIALS:
"Sentiment Analyzer"
ROLES:
AmazonSNSFullAccess
AWSLambdaBasicExecutionRole
ComprehendFullAccess
FUNCTION NAME:sentiment-analysis
FUNCTION CODE:
import json
import boto3
Initialize AWS clients
comprehend = boto3.client("comprehend")
sns = boto3.client("sns")
Replace with your correct SNS Topic ARN (without the extra subscription ID)
SNS_TOPIC_ARN = "arn:aws:sns:us-east-1:050752635754:SentimentAlerts"
def lambda_handler(event, context):
try:
Parse input text
body = json.loads(event.get("body", "{}"))
text = body.get("text", "").strip()
if not text:
return {
"statusCode": 400,
"body": json.dumps({"error": "No text provided for sentiment analysis"})
}
Perform sentiment analysis
response = comprehend.detect_sentiment(Text=text, LanguageCode="en")
sentiment = response["Sentiment"]
Prepare SNS message
message = f"Sentiment Analysis Result: {sentiment}\n\nText: {text}"
Publish message to SNS
sns.publish(TopicArn=SNS_TOPIC_ARN, Message=message)
return {
"statusCode": 200,
"body": json.dumps({"sentiment": sentiment, "message": "Notification sent successfully!"})
}
except Exception as e:
return {
"statusCode": 500,
"body": json.dumps({"error": str(e)})
}
LAMBDA EVENT CODE:
{
"body": "{\"text\": \"I hate this service!\"}"
}
SNS NAME:SentimentAlerts
URL:https://iojdihzccj.execute-api.us-eas...
BODY:
{
"text": "i hate aws!!"
}
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: