Serverless Blog
all
guides & tutorials
user stories
operations & observability
engineering culture
news

A Serverless Twitter bot helps house Camp Fire victims

written by  
  Eric Wyne

For those of you not living in Northern California, I’m sure you’ve at least heard of our most devastating wildfire to date: Camp Fire, which spread out north of Sacramento, taking out entire towns like Paradise, Concow and Magalia.

I live in Chico, a mere twenty minutes from Paradise, where thousands of people lost their homes in a span of hours. Especially because of my proximity, the devastation from the fire was really poignant for me. Many of these people weren’t strangers; they were my friends.

I knew I wanted to do everything I could to help out, and housing was the biggest need.

There was a website, campfirehousing.org (created by nvpoa.org), where individuals could post about temporary housing opportunities for Camp Fire victims—extra bedrooms in homes, and things like that. The idea behind that website was fantastic, but it was missing some critical features that I knew would help people find housing faster.

For instance, there was no way to be notified when a new housing opportunity was posted, and it was hard to tell which postings were still open. People who were looking for places to stay still had a hard time seeing what was even truly available, and jumping on new housing as it got added to the site.

So I thought, hm. How long would it take to throw some code together that would notify people of new housing opportunities as soon as they were posted?

The Serverless Twitter bot

I decided to create a Twitter bot that would tweet out housing opportunities as they were added to campfirehousing.org. Anyone who was interested could follow the bot on Twitter and stay on top of what was newly-added and available.

I chose to power the app with a serverless backend for a couple reasons. For starters, it was going to be the quickest way to get the app off the ground and helping people. On top of that, due to Lambda’s generous free tier, it was almost certainly going to cost me nothing.

The whole thing was built with the Serverless Framework + AWS Lambda. I was able to get this entire project off the ground in only two hours, from initial research to first successful tweet.

Building the bot: just one function

Campfirehousing.org didn’t have an RSS feed, so I had to set up a CRON (scheduled function) that would check the website for updates every five minutes, and read the values from a Google Sheet. When there were new postings, my Twitter bot would tweet them out.

The tweets included important info like price, city, availability date, whether pets were allowed, and a short description. I scraped all this data directly from campfirehousing.org, and truncated the full text down to 280 characters when applicable.

Overall, the code is just a pretty simple and straightforward single function; check it out here and feel free to use it in your own projects!

You can also find the full Twitter stream at @CampFireHousing.

Challenges along the way

The hardest part of this entire project was actually figuring out how to handle dates. I was working locally on my machine in PST, but when I ran code in AWS it defaulted to GMT.

I ended up having to tell Lambda function to run as though it was in PST, so I could have the same experience locally as in the cloud.

A special shout-out to the Serverless Framework and open source

Working on side projects like these make me realize how amazing the open source community is.

I’m grateful for the open source projects that allow date manipulation and quick tweet integrations, and for how easy the Serverless Framework made it to ship my code into the world. The serverless-plugin-typescript plugin made writing TypeScript functions in Lambda super easy, for example.

It’s just awesome to know I can think of a project, and be able to lean on open source contributions like this to make it happen much quicker and easier than I could do it all alone.

A note in closing from the Serverless team

We absolutely love the way that serverless technologies are enabling people to build applications that serve their communities like this!

If you’ve done something for a non-profit with Serverless, please don’t hesitate to share it with us so we can help you spread the word. We want your code to help others do the same.

#opensourceforever

About Eric Wyne

Eric is a Senior Software Engineer at Grade Potential.

 - 22.03.17

How To Use AWS Lambda & API Gateway to Send Shipment Tracking Updates via SMS with Shippo & Twilio

A guide on using Serverless to create an AWS Lambda function that triggers on updates sent to AWS API Gateway to send SMS updates via Twilio for shipments you're tracking using Shippo

written by Richard Moot

news - 10.07.18

Serverless updates - SQS events, private endpoints, Event Gateway open source

Serverless Framework v1.28 adds SQS support & private endpoints for API Gateway, plus tons of updates to Event Gateway open source.

written by Andrea Passwater

Join 16,000 other developers and keep up to speed on the latest serverless news and releases.

Join 16,000 other developers and keep up to speed on the latest serverless news and releases.

Made with love in San Francisco + Atlanta, Austria, Germany, Pakistan, Poland, Nebraska & Thailand

Serverless, Inc. © 2018

Join our monthly newsletter to get the latest Serverless news, updates and happenings.