This Guidance helps you gain insight into what your customers are saying about your products and services on social media websites, such as Twitter. Instead of filtering out Twitter data manually, you can build a near real-time alert system that consumes data from Twitter and classifies tweets using a pre-trained model from Hugging Face Hub.
Architecture Diagram
Step 1
An Amazon Elastic Container Service (Amazon ECS) task runs on serverless infrastructure managed by AWS Fargate and maintains an open connection to the Twitter API.
Step 2
The Twitter Bearer token is securely stored in AWS Systems Manager Parameter Store, and the container image is hosted on Amazon Elastic Container Registry (Amazon ECR).
Step 3
When a new tweet arrives, it’s placed into an Amazon Simple Queue Service (SQS) queue.
Step 4
The logic of the solution resides in AWS Lambda function microservices, coordinated by AWS Step Functions.
Step 5
A Hugging Face classification model is hosted on Amazon SageMaker Serverless Endpoints.
Step 6
Amazon Comprehend extracts sentiment, key phrases, and entities. If possible, Amazon Comprehend extracts location.
Step 7
Amazon Location Service transforms a location name into coordinates.
Step 8
The tweet and metadata are sent to Amazon Simple Storage Service (Amazon S3), and Amazon Athena queries the processed tweets with standard SQL.
Step 9
Amazon Lookout for Metrics looks for anomalies in the volume of mentions per category. Amazon Simple Notification Service (Amazon SNS) sends an alert to users when an anomaly is detected.
Step 10
We recommend setting up a Amazon QuickSight Dashboard so that business users can easily visualize insights.
Well-Architected Pillars
The AWS Well-Architected Framework helps you understand the pros and cons of the decisions you make when building systems in the cloud. The six pillars of the Framework allow you to learn architectural best practices for designing and operating reliable, secure, efficient, cost-effective, and sustainable systems. Using the AWS Well-Architected Tool, available at no charge in the AWS Management Console, you can review your workloads against these best practices by answering a set of questions for each pillar.
The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.
-
Operational Excellence
You can roll back changes made to the architecture using an AWS CloudFormation template. If deployments fail in Fargate and Lambda, they can be automatically rolled back to previous versions.
-
Security
To deploy this architecture, you must set up an Identity and Access Management (IAM) user or role with the appropriate permissions to services. Additionally, data stored in Amazon S3 is encrypted with an AWS Key Management Service (AWS KMS) key.
-
Reliability
Data is stored in Amazon S3, an object storage service that offers 99.999999999% durability. If your data is business critical, you can implement S3 Cross-Region Replication (CRR) to replicate the data in other AWS Regions for disaster recovery. When anomalies above a certain threshold occur, Amazon SNS sends you alerts so you can quickly resolve the issue.
-
Performance Efficiency
AWS handles administrative tasks for managed services, such as patches and updates to help maintain performance efficiency. Services like Lookout for Metrics and Amazon Location are specifically designed for detecting anomalies and adding location data to applications, respectively.
-
Cost Optimization
In this Guidance, the majority of data is consumed directly in AWS through Athena and QuickSight, reducing the amount of data transfer charges. Data transfer out through Amazon SNS only occurs for anomalies that exceed user-defined thresholds. Additionally, this architecture uses serverless services, so that you only pay for the resources you consume.
-
Sustainability
Serverless services scale with usage so you do not have to run idle infrastructure to address growth in demand.
Implementation Resources
The sample code is a starting point. It is industry validated, prescriptive but not definitive, and a peek under the hood to help you begin.
Related Content
Build a news-based real-time alert system with Twitter, Amazon SageMaker, and Hugging Face
Disclaimer
The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.