DEV Community

Cover image for Why I'm automatically deleting my old tweets using AWS Lambda
Victoria Drake
Victoria Drake

Posted on • Updated on

Why I'm automatically deleting my old tweets using AWS Lambda

From now on, my tweets are ephemeral. Here's why I'm deleting all my old tweets and the AWS Lambda function that does it for free.

Stuff and opinions

I've only been a one-bag nomad for a little over a year and a half. Before that, I lived as most people do in an apartment or a house. I owned furniture, more clothing than I strictly needed, and enough "stuff" to fill at least a few moving boxes. If I went to live somewhere else, moving for school or family or work, I packed up all my things and brought them with me. Over the years, I accumulated more and more stuff.

Adopting what many would call a minimalist lifestyle has rapidly changed a lot of my longstanding views. Giving away all my stuff (an idea I once thought to be interesting in principle but practically a little bit ridiculous) has become normal. It's normal for me, now, to not own things that I don't use on a regular basis. I don't keep wall shelves packed with old books or dishes or clothing or childhood toys because those items aren't relevant to me anymore. I just keep fond memories, instead.

Imagine, for a moment, that I still lived in a house. Imagine that in that house, on the fridge, is a drawing I made when I was six-years-old. In the bottom right corner of that drawing scribbled in green crayon are the words "broccoli is dumb - Victoria, Age 6."

If you were in my house and saw that drawing on the fridge, would you assume that the statement "broccoli is dumb" comprised an accurate and current account of my opinions on broccoli? Of course not. I was six when I wrote that. I've had plenty of time to change my mind.

Social media isn't social

I have a friend whom I've known since we were both in kindergarten. We went through grade school together, then spoke to and saw each other on infrequent occasions across the years. We're both adults now. Sometimes when we chat, we'll recall some amusing memory from when we were younger. The nature of memory being what it is, I have no illusion that what we recall is recounted with much accuracy. Our impressions of things that happened - mistakes we made and moments of victory alike - are coloured by the experiences we've had since then, and all the things we've learned. An awkward moment at a school colleague's birthday party becomes an example of a child learning to socialize, instead of the world-ending moment of embarrassment it probably felt like at the time.

This is how memory works. In a sense, it gets updated, as well it should. People living in small communities remember things that their neighbour did many years ago, but recall them in the context of who their neighbour is now, and what their current relationship is like. This re-colouring of history is an important part of how people heal, make good decisions, and socialize.

Social media does not do this. Your perfectly preserved tweet from five days or five years ago can be recalled with absolute accuracy. For most people, this is not particularly worrying. We tend to tweet about pretty mundane things - things that pop into mind when we're bored and want someone to notice us. Individually, usually, our old tweets are pretty insignificant. In aggregate, however, they paint a pretty complete picture of a person's random, unintentionally telling thoughts. This is the problem.

The assumption made of things written in social media and on Twitter specifically is a very different assumption than you might make about someone's notepad scribble from last week. I'm not endeavoring to speculate why - I've just seen enough cases of someone getting publicly flogged for something they posted years ago to know that it does happen. This is weird. If you wouldn't assume that a notepad scribble from last week or a crayon drawing from decades ago reflects the essence of who someone is now, why would you assume that an old tweet does?

You are not the same person you were last month - you've seen things, read things, understood and learned things that have, in some small way, changed you. While a person may have the same sense of self and identity through most of their life, even this grows and changes over the years. We change our opinions, our desires, our habits. We are not stagnant beings, and we should not let ourselves be represented as such, however unintentionally.

Ephemeral tweets

If you look at my Twitter profile page today, you'll see fewer tweets there than you have fingers (I hope). I'm using ephemeral - a lightweight utility I wrote for use on AWS Lambda - to delete all my tweets older than a few days. I'm doing this for the same reason that I don't hang on to stuff that I no longer use - that stuff isn't relevant to me anymore. It doesn't represent me, either.

The code that makes up ephemeral is written in Go. AWS Lambda creates an environment for each Lambda function, so ephemeral utilizes environment variables for your private Twitter API keys and the maximum age of the tweets you want to keep, represented in hours, like 72h.

var (
    consumerKey       = getenv("TWITTER_CONSUMER_KEY")
    consumerSecret    = getenv("TWITTER_CONSUMER_SECRET")
    accessToken       = getenv("TWITTER_ACCESS_TOKEN")
    accessTokenSecret = getenv("TWITTER_ACCESS_TOKEN_SECRET")
    maxTweetAge       = getenv("MAX_TWEET_AGE")
    logger            = log.New()
)

func getenv(name string) string {
    v := os.Getenv(name)
    if v == "" {
        panic("missing required environment variable " + name)
    }
    return v
}
Enter fullscreen mode Exit fullscreen mode

The program uses the anaconda library. It fetches your timeline up to the Twitter API's limit of 200 tweets per request, then compares each tweet's date of creation to your MAX_TWEET_AGE variable to decide whether it's old enough to be deleted. After deleting all the expired tweets, the Lambda function terminates.

func deleteFromTimeline(api *anaconda.TwitterApi, ageLimit time.Duration) {
    timeline, err := getTimeline(api)

    if err != nil {
        log.Error("Could not get timeline")
    }
    for _, t := range timeline {
        createdTime, err := t.CreatedAtTime()
        if err != nil {
            log.Error("Couldn't parse time ", err)
        } else {
            if time.Since(createdTime) > ageLimit {
                _, err := api.DeleteTweet(t.Id, true)
                log.Info("DELETED: Age - ", time.Since(createdTime).Round(1*time.Minute), " - ", t.Text)
                if err != nil {
                    log.Error("Failed to delete! ", err)
                }
            }
        }
    }
    log.Info("No more tweets to delete.")

}
Enter fullscreen mode Exit fullscreen mode

Read the full code here.

For a use case like this, AWS Lambda has a free tier that costs nothing. If you're any level of developer, it's an extremely useful tool to become familiar with. For a full walkthrough with screenshots of how to set up a Lambda function that tweets for you, you can read this article. The set up for ephemeral is the same, it just has an opposite function. :)

I forked ephemeral from Adam Drake's Harold, a Twitter tool that has many useful functions beyond keeping your timeline trimmed. If you have more than 200 tweets to delete at first pass, please use Harold to do that first. You can run Harold with the deletetimeline flag from your terminal.

For sentiment, you may like to download all your tweets before deleting them.

Why use Twitter at all?

In anticipation of the question, let me say that yes, I do use Twitter besides just as a bucket for my Lambda functions to fill and empty. It has its benefits, most related to what I perceive to be its original intended purpose: to be a means of near-instant communication for short, digestible pieces of information reaching a widespread pool of people.

I use it as a way to keep tabs on what's happening right now. I use it to comment on, joke about, and commiserate with things tweeted by the people I follow right now. By keeping my timeline restricted to only the most recent few days, I feel like I'm using Twitter more like it was meant to be used: a way to join the conversation and see what's happening in the world right now - instead of just another place to amass more "stuff."

Top comments (22)

Collapse
 
k4ml profile image
Kamal Mustafa

Interesting. I have archivist mindset and obsess about continuity. So I'm doing basically the opposite of what you're doing. For example, I set up IFTTT to post my tweets into Blogger so it's better archived by year and month. This also explain why I have so many old stuff that not being used anymore at my home :(

Collapse
 
nektro profile image
Meghan (she/her)

Great idea! I wish there were better ways to view old tweets :(

Collapse
 
k4ml profile image
Kamal Mustafa

You can download all your tweets and search for it locally.

Collapse
 
ben profile image
Ben Halpern

I have completely forgotten what some of my old tweets might have been. I'm pretty sure young Ben was pretty sensible but I really can't remember.

I may just have to make use of this myself.

Collapse
 
victoria profile image
Victoria Drake

You know there's a drunk tweet in there, somewhere. :p

Collapse
 
rhymes profile image
rhymes • Edited

Thanks for this.

I've been off Twitter and Facebook for more than a month and although I definitely do not miss FB, I miss Twitter for exactly what you said: keeping tabs on what's happening right now (though sometimes I end up bookmarking links on Twitter because I don't have time to read them :D)

I have way too many tweets (around 12k, I'm not kidding and my account is 9 years old). I'm going to consider everything you said and probably start deleting the first few years. By memory I have no idea what the heck I had been yapping about in 2009 so why keep it there?

On the technical side: thanks for reminding me that I need to get more acquainted with Lambda.

On the personal side: I would love read more about your experience about being a digital nomad and a nomadic developer. I also think it would contribute a lot to dev.to, I guess most people here are not digital nomads :-)

I'm a remote developer. I donated most of my clothes twice already but I can't find myself to go full Marie Kondo on my things. I'm definitely aware of this issue and after having been in the same city for a few years now I look around and see that I own too much stuff.

Collapse
 
victoria profile image
Victoria Drake

I find that my perspective is clearest when I'm about to leave one location for another, and when I've just arrived somewhere new. The experience of change really forces you to consider what (more than just tangible things) is really necessary and helpful to your own life.

I blog infrequently about the way I live at herOneBag.com :)

Collapse
 
rhymes profile image
rhymes

Thank you!

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

I am a big fan of your writing and storytelling. Excellent article Vicky! I love your philosophy on Twitter and the reasons you have to erase old tweets. After reading it, I feel like all tweets should have an expiration.

Collapse
 
y0mbo profile image
John Uhri

Unfortunately, it means that people who have liked or retweeted things you have posted now lose access to that information. I followed one person whose Twitter feed was a gold mine of information and who decided to delete their entire Twitter account. That was a great loss to the software development community. He's back on Twitter now, but I don't follow him anymore.

Collapse
 
victoria profile image
Victoria Drake • Edited

At risk of sounding cavalier, this is an excellent example of why information controlled by other people/organizations/companies is not a reliable personal bookmarking service. :)

Thankfully there (1) are (2) options (3) for automatically saving things you like on Twitter to accounts in your control. With a little ingenuity, you can also roll your own program to do this (maybe not with Lambda, though).

That said, still my favorite and most reliable form of saving information is taking notes on paper. Writing also helps you internalize the information, so that's a double win.

Collapse
 
howardjones profile image
Howard Jones

Not just information but conversations. I have several friends who I used to enjoy a conversation with on social media, which are a strange one-sided affair now they've deleted their accounts. It almost feels like a betrayal that someone gets to veto a shared experience like that.

Collapse
 
rjpsyco009 profile image
Ryan Norton

You make a really good point on the perspective of old tweets. So many celebs, YouTubers, etc that I follow end up having a story on them because of a tweet that they may not even remember, nor agree with now because, yes, we change. All the time.
I really enjoyed your concept. I'd love to be able to search my tweets by month or year to see if I should stick a fork in your code and help myself πŸ˜…
Great Post!

Collapse
 
victoria profile image
Victoria Drake

Hey Ryan! If you download your twitter data at the link I mentioned, you'll have a local archive of your tweets that you can browse by year and month. I'm glad you like the post!

Collapse
 
rjpsyco009 profile image
Ryan Norton

Awesome! Thanks so much!

Collapse
 
valerauko profile image
Vale

Personally I enjoy looking back at old stuff occasionally, and it comes really handy when I can just search for that memory "from somewhere in 2013 that I don't recall precisely but I tweeted about it for sure".

But if I were to do it still, the Mastodon instance Pawoo.jp I use has a feature to expire posts built-in.

Collapse
 
dmerand profile image
Donald Merand

This is a very cool idea and for some, likely a much more reasonable one than simply leaving Twitter entirely. Thanks for sharing!

Collapse
 
victoria profile image
Victoria Drake

Thank you!

Collapse
 
vbordo profile image
Victor Bordo

This is fantastic Vicky, thanks so much!

Collapse
 
victoria profile image
Victoria Drake

You're very welcome!

Collapse
 
miglen profile image
Miglen πŸ„

Great one, also the reasoning totally makes sense!

I've written a simpler script in python to do the work: gist.github.com/miglen/56ee2bc8a4e...

Also, you may specify a list of Id's to keep.

Collapse
 
albertogarrido profile image
Alberto Garrido • Edited

This is awesome, thanks!!!

I am thinking of doing the same in more places (facebook, instagram for example). Instead of just deleting, backup and delete "just in case"