DEV Community

Cover image for Quest: Build a Twitter Bot
Owen Collier-Ridge
Owen Collier-Ridge

Posted on • Updated on

Quest: Build a Twitter Bot

Intro

Hey, thanks for reading this. I'm Owen, I'm a software engineer, and I produce technical learning content, follow me on gumroad.

Today I'm giving you a quest to build a Twitter bot on AWS Lambda.

Quest Log from Runescape

This quest might be easy for you, if you've used AWS and the Twitter API before, or it might be a bit more of a challenge. But I'm here, and all the answers to your questions are in this post, so fear not.

If you want to jump ahead and deploy the application: here is the source code.

Main Quest Objectives

Grab the Shiny Things!

  • Obtain the Secrets of Twitter, API keys.
    • Sign up for a Developer Account at https://developer.twitter.com/.
    • Make an App, this will get you CONSUMER_KEY and CONSUMER_SECRET from the console. Then generate your ACCESS_KEY and ACCESS_SECRET in the console.
  • Cast an obfuscation spell on your Secrets, Store them as Encrypted Secrets in AWS.
  • Invoke my scrolls to make the bot come to life, deploy it to AWS with my scripts.

Let's get started!

Twitter Setup

Apply for a developer account at https://developer.twitter.com/, this takes about 5 minutes.

We need to get four secrets from Twitter to use their API:

  • ACCESS_SECRET
  • ACCESS_TOKEN
  • CONSUMER_KEY
  • CONSUMER_SECRET

After you make an app you can get your CONSUMER_KEY and CONSUMER_SECRET from the Twitter API console.

Then you can generate your ACCESS_SECRET and ACCESS_TOKEN in the API console as well.

Generating Twitter Secrets

Keep going, we're almost there!

Look at those Scrolls!

AWS Setup

You can place your secrets in SSM via the API

aws ssm put-parameter --name ACCESS_SECRET --value XXXXYYYYYZZZZZAAAABBBCCCC --type SecureString

Or you can just use the AWS console.
SSM Console

Everything is perfectly in place.

Deployment

Clone the repo.

git clone https://github.com/BoraxTheClean/TwitterBot.git
cd TwitterBot

Modify this line of script.sh and replace owen-lambda-bucket with your own s3 bucket located in the region you are deploying into.

BUCKET=owen-lambda-bucket

Then simply run

make deploy

Quest Complete!

Make it Yours!

  • Use it to Tweet out your art.
  • Promote your business with a Bot.
  • Let people invoke your bot by @'ing it.
  • Customize your own Twitter experience with your bot.

Have fun coding! And be sure to follow me on GumRoad for new courses and updates!

Find me on Twitter.

Shoot me an email.

Coming Soon

Side Quest

  • Learn how the Twitter Bot was built.
    • Read through my comments on the infrastructure used.
    • Read through the simple python code.

Top comments (0)