⚡Using FaaS to Create FaaS🍺

Written by devlead | Published 2017/02/16
Tech Story Tags: azure | cloud-computing | azure-functions | serverless | onedrive

TLDRvia the TL;DR App

Using Azure Functions a.k.a. functions as a service a.k.a. FaaS to create FaaS a.k.a. Foley as a Service

Recently I did this blog post

GitHub statuses made easy with FaaS_Using Azure Functions to automate your pull requests validation_hackernoon.com

and when I tweeted it got this reply

My gut reaction this has to be done!

…and it has to be done in a “enterprise way”…so tonight I gave my self 10 minutes to everything A-Z (blog post excluded) come up with a solution 8 minutes and 56 seconds later my proof of concept was up & running.This is what I came up with

Obvious right? Lets go through it step by step, crazy as it is — it’s actually a pretty good show case on what very easily can be done.

The Service

So what is one of the best services Foley provides? Obviously beer pick of the week! So why not a Twitter bot that gives people random beer picks!

Twitter

The first step, create epic twitter account:

Foley as a Service (@FoleyAsAService) | Twitter_The latest Tweets from Foley as a Service (@FoleyAsAService)_twitter.com

IFTTT

Twitter APIs are cumbersome, lets stand one the shoulders of giants, IFTTT is easy and free — an paid alternative could’ve been i.e. Azure Logic Apps which has a search Twitter trigger.

So a setup applet triggered when my newly created account gets mentioned. IFTTT don’t post to Azure Functions yet, but they can create GitHub issues!

GitHub

It’s not super fast it takes between a minute and an hour for IFTTT to pick up on a mention, but when it finally does it works like a charm

How does this help us you say? Well GitHub can trigger Azure Functions when issues are created.

Just select individual events and narrow it down to issues — brilliant I say!

Azure Function 1

Our first Azure function will just receive the GitHub webhook event, cherry pick needed data, parses the GitHub comment and then queues it to an Azure Storage Queue

The queue item GitHubIssue class is just a poco nothing fancy and looks like this

Azure Function 2

Our second function subscribes to the Azure Storage Queue and reuses the same GitHubIssue class to get a typed message when triggered.

Now to the fun part, NOSQL is hot buzzword nowadays, I wanted and solution that Mary Jo with ease could administrate herself…

…and what better solution than using Notepad to administrate our beer selections, how is this even possible you say?

Well obviously we use OneDrive to store the file easily editable from Notepad! As Azure Functions now in preview as support for binding parameters to a file on OneDrive! So then all we need to do is read the lines from the file and pick one at random and serve as a tweet. Wouldn’t say Twitters API is too complex, but the clock was ticking and Buffer provides a far simpler API, it’s just a HTTP post, which also lets me retweet original tweet with a comment.

So what does the function look like, for hasty work actually it’s not that bad (IMHO).

And it’s bindings is just queue & external file coming in

External files are in preview and not yet generally available but it already supports several services, so I can see this becoming really useful in the future!

The result

Tweet @FoleyAsAService and as long as I haven’t ran out of credits it’ll retweet you a beer pick within 60 minutes

Conclusion

Starting out as a joke and a challenge to myself how much could be done in 10 minutes — I find myself it’s actually kinda amazing how easy things that used to be complex can be. Obviously the code needs refactoring, error handling and testing — but doing a PoC A-Z using several online services is pretty cool.

So thanks for the idea Mary Jo! It was a fun exercise in FaaS — Foley as a Service🍺

Update

Foley As A Service was featured on Windows Weekly Episode 506


Published by HackerNoon on 2017/02/16