Quest: Build a Twitter Bot
Tags: tutorial, aws, lambda, python
Published: 2020-06-05 21:00:13

---
title: Quest: Build a Twitter Bot
published: true
description: Build a Twitter Bot on AWS Lambda. 
tags: Tutorial, AWS, Lambda, Python
cover_image: https://raw.githubusercontent.com/BoraxTheClean/TwitterBot/master/TwitterBot.png
---
# Intro

Hey, thanks for reading this. I'm [Owen](https://owen.dev), I'm a software engineer, and I produce technical learning content, [follow me on gumroad.](https://store.owen.dev)

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

![Quest Log from Runescape](https://runescape.wiki/images/8/88/Quest_List_interface.png?47fc5)

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.](https://github.com/BoraxTheClean/TwitterBot)

# Main Quest Objectives

![Grab the Shiny Things!](https://www.pcgamesn.com/wp-content/uploads/2019/10/RS_new-skill_Archaeology-900x506.jpg)

  - 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._
    - [Set up your AWS Account,](https://store.owen.dev/#EpfNp) if you don't already have one.
    - Put your Twitter Secrets in [SSM Parameter Store as SecureStrings.](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)
  - 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](https://dev-to-uploads.s3.amazonaws.com/i/k0rs45pazkja17khaqns.png)

Keep going, we're almost there!

![Look at those Scrolls!](https://massivelyop.com/wp-content/uploads/2019/07/hearthstone-uldum-04.jpg)

# AWS Setup

You can place your secrets in SSM via the API

```bash
aws ssm put-parameter --name ACCESS_SECRET --value XXXXYYYYYZZZZZAAAABBBCCCC --type SecureString
```
Or you can just use the AWS console.
![SSM Console](https://raw.githubusercontent.com/BoraxTheClean/TwitterBot/master/SSM.png)

![Everything is perfectly in place.](https://gamepedia.cursecdn.com/hearthstone_gamepedia/c/c7/Golden_Kobold_full.jpg?version=8c4555675fd50bc20c138a13f22e110e)

# Deployment

Clone the repo.
```bash
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.

```Make
BUCKET=owen-lambda-bucket
```

Then simply run
```bash
make deploy
```
![Quest Complete!](https://www.nicepng.com/png/detail/118-1186112_quest-complete-quest-runescape.png)

# 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!](https://store.owen.dev)

[Find me on Twitter.](https://twitter.com/AWSOwen)

[Shoot me an email.](mailto:owen@owen.dev)

# 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.