jlhood / tweet-sentiment-python

Python implementation of serverless app that publishes sentiment score metrics of tweets to CloudWatch Metrics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tweet-sentiment

Build Status

This serverless app processes tweets for a given Twitter search, calls Amazon Comprehend to do sentiment analysis on the tweet text, and publishes the sentiment scores as custom metrics to Amazon CloudWatch Metrics.

App Architecture

App Architecture

  1. The aws-serverless-twitter-event-source app is nested and configured to periodically invoke a Lambda function to process tweet search results. The app is used in stream mode, meaning it will remember which tweets have already been processed and only perform sentiment analysis on new tweets.
  2. The Lambda function is invoked with a batch of tweets to process and calls Amazon Comprehend to get sentiment scores on the text of the batch of tweets.
  3. Tweet sentiment scores are sent as custom metrics to CloudWatch and logged to the Lambda function's CloudWatch Logs log group.
  4. The app includes a CloudWatch Dashboard for convenient monitoring of tweet sentiment metrics and logging.

Installation Instructions

  1. Create an AWS account if you do not already have one and login.
  2. Since this app uses aws-serverless-twitter-event-source as a nested app to provide tweet search results, you need to follow the steps to create and install Twitter API keys for the aws-serverless-twitter-event-source app to use when calling the Twitter search API.
  3. Once you've installed the Twitter API keys, go to the tweet-sentiment Serverless Application Repository page and click "Deploy"
  4. Provide the required app parameters (see parameter details below) and click "Deploy"

Using the CloudWatch Dashboard

The app automatically creates a CloudWatch Dashboard for easy viewing of aggregate sentiment scores as well as top positive/negative tweets. Here are example screenshots where the app was configured to search for 'serverless':

Dashboard Metrics Screenshot

Dashboard Logs Screenshot

Amazon Comprehend returns 4 different sentiment scores for each tweet: Positive, Negative, Neutral, and Mixed. Each score is a value from 0 to 1 representing the likelihood that the sentiment was correctly detected. See the Amazon Comprehend documentation for more information on Amazon Comprehend's sentiment analysis.

The app also logs sentiment scores for each tweet to the TweetSentiment Lambda function's log group. The sentiment scores are logged using a structured format that allows for querying results using CloudWatch Insights. This allows you to drill down and find specific tweets based on their sentiment scores.

The included CloudWatch Dashboard displays the top positive and negative tweets within the selected time period. If you would like to run your own custom queries against the log data using CloudWatch Insights, on the dashboard, go to one of the CloudWatch Insights widgets and click on the "View in CloudWatch Insights" icon to the right of the widget title.

Dashboard Logs Icon Screenshot

This will take you to the CloudWatch Insights console with the query text area pre-populated with the same query used to generate the Dashboard widget. You can then modify and run the query.

To learn more about querying logs using CloudWatch Insights, see the documentation.

App Parameters

  1. SearchText (required) - Search text to pass to Twitter. You can experiment with the Twitter search API at https://twitter.com/search-home
  2. PollingFrequencyInMinutes (optional) - Frequency (in minutes) to poll for new tweets. Default: 5
  3. DashboardName (optional) - CloudWatch dashboard name. If not specified, defaults to let CloudFormation name the Dashboard.
  4. DashboardPeriodInSeconds (optional) - Period (in seconds) for graphs on CloudWatch dashboard. Valid values are 60 (1 minute), 300 (5 minute), or 3600 (1 hour). Default: 300 (5 minutes)
  5. LogLevel (optional) - Log level for Lambda function logging, e.g., ERROR, INFO, DEBUG, etc. Default: INFO

App Outputs

  1. TweetSentimentFunctionName - TweetSentiment function name.
  2. TweetSentimentFunctionArn - TweetSentiment function ARN.
  3. DashboardName - CloudWatch Dashboard name.

License Summary

This code is made available under the MIT license. See the LICENSE file.

About

Python implementation of serverless app that publishes sentiment score metrics of tweets to CloudWatch Metrics

License:MIT License


Languages

Language:Python 91.6%Language:Makefile 8.4%