Building a Twitter Bot with AWS Serverless

An engineer excelled in developing data solutions using Big Data Technologies and Machine Learning algorithms in the Cloud infrastructure.
Search for a command to run...

An engineer excelled in developing data solutions using Big Data Technologies and Machine Learning algorithms in the Cloud infrastructure.
No comments yet. Be the first to comment.
As part of this series, I will be highlighting the Amazon Web Services (AWS) services and practices that I use in both my personal and professional capacities.
Airflow is a tool to orchestrate complex workflow which was created at Airbnb in 2014. Airflow gained significant traction across several organizations in recent days due to the ability to create complex data pipelines with ease. The Airflow user int...
Git is a source code management system that keeps track of the changes made to their codebase and collaborates with other team members. It is commonly used for source code management in software development, but it can track changes to any set of fil...

What It Is and Why It Matters?

It's no secret that cyber intelligence pros must have data engineering skills. But what exactly is data engineering? Data engineering is a skill that's used to collect and analyze data. Then, it can be used to understand the data's quality and make p...

Build, deploy, and manage mobile and web apps that need real-time or offline data are simple with AWS AppSync, a fully managed serverless GraphQL service. Your apps may securely access and work with data stored in AWS services like Amazon DynamoDB, A...

AWS re: Invent is a learning conference hosted for the global cloud computing community with in-person and virtual content where they announced many new features and updates. This post is the summary of the list of changes within the Data & Analytics...

Sharing my experience of how I am running the Twitter Bot on AWS for almost free using AWS serverless technologies.
Social Bot is nothing but a program that mimics the behaviors of a user based on the rules you set. Twitter is one of the BOT friendly platforms where you can automate a lot of things from liking, re-posting, follow, unfollow, and messaging using their API.
Before we get down to the nitty-gritty of how it works, there is an official guidelines from Twitter to follow whenever we create a bot.

I've created this account last year in June 2020, but it outperformed my other account which I have been using for 10+ years with a lot more followers, tweets, and engagements so the same content I post in this account reaches much more audience than the actual one.
To create your bot all we need is a Twitter account and an AWS account to host your application.

Lambda is a serverless compute service from AWS that lets you write and run your own code without managing any servers. Lambda comes with 1 million execution and 400,000 GB-seconds of compute time for free. It also supports multiple languages such as Node.js, Python, Java, and many more. I've used Python to develop this bot which will run multiple times a day to source the best content based on the keywords and hashtags.
Secrets Manager helps to keep our secret keys secure within AWS. The cost is based on the number of keys so it may cost you ~$1 to keep our Twitter access keys securely.
Alternatively, you can also keep the keys in your Lambda environment variable which won't cost you anything, but never store your keys straight in the code as a best practice.
DynamoDB is a NoSQL database from AWS which allows you to store the data in key-value pairs. I am using this to store the metadata of the content I shared on my Twitter to avoid repetitive content in my feed. Since am using on-demand, the cost is based on the read and writes so in my case it's costing me less than $1 per month.
CloudWatch is a monitoring and observability tool which provides data to make actionable insights to monitor our application. I am writing all the Lambda logs back to CloudWatch to keep track of how it is progressing. We can run this within the free tier so there is no additional cost to keep these logs.
Lastly, I am using Slack to monitor the content it shares. Now you may have a question why can't we directly use the Twitter app to check now and then, having that comes as a message in Slack is so much more comfortable than checking my Twitter feed.
Serverless architectures provide great benefits, but mainly the scalability and the cost. There are paid services to manage your Twitter content, but to run our own is nearly free using a platform like AWS. Similarly, there are several applications and use-cases you can develop using serverless technologies.