Serverless Computing - What is it?
Serverless is a concept in Cloud Computing that has been growing in popularity over the last 12 months. It is very powerful and has a lot of potential. In this post, I hope to help explain what Serverless is, how it can be used and some examples of how it is being used in the industry.
So what is it?
Traditionally, when developing web applications or API’s, you need to focus a lot of the time on the infrastructure that makes that work. Even in the cloud, that might involve figuring out autoscaling requirements, do you need a load balancer or not, and various other specifics that you may or may not need in order to deploy your application.
Well, the idea behind Serverless is to write application code and "forget" about the infrastructure that makes it work. In its simplest form this could be a small script that simply returns a message of the day when executed: you write your code and upload it to the cloud (in AWS this would take shape as a Lambda function), apply a little configuration and voila, your code/application is now live and can be accessed either through dedicated API’s you create or through API calls specific to your cloud platform.
The simple idea of removing the concern on the compute resources running behind the scenes allows solution developers to focus on what matters – the solution. It takes away the need to worry about how many servers you need or what CPU resources you might want. You have control over some areas like how long you wish your code to be allowed to run for (to prevent "broken" code running forever) or how much memory you might expect to use. Most importantly, you have full control over the security aspects of the serverless application – such as which IAM Role the Lambda function should use and the permissions of said role.
Put simply, you write the code and let AWS worry about the rest (mostly).
Each of the major cloud providers’ serverless focused services are:
- AWS Lambda – "Run code without thinking about servers. Pay for only the compute time you consume".
- Microsoft Azure Functions – "Listen and react to events across your stack"
- Google Cloud Platform Cloud Functions – "Lightweight, event-based, asynchronous compute solution that allows you to create small, single-purpose functions that respond to cloud events without the need to manage a server or a runtime environment".
What can you do with serverless?
The quick example above explains how you might use the serverless concept for something super simple like returning a message, but you can do so much more. Think about traditional web applications or popular API’s – these sorts of applications are great candidates for serverless as they are simple request-based interactions. Once the page has loaded, it can be returned to the client and used like any traditional version of the same application.
Using supported languages and serverless frameworks, you are able to develop web applications that you would normally spend more time installing and configuring than developing for. You simply write your application to work with the framework (such as Flask for Python or Serverless for NodeJS) and deploy to AWS/Azure/Google Cloud etc and let their respective services handle the underlying compute provisioning.
Similar to normal web applications, the Serverless model can be applied to building API’s that might be made available to internal or external developers to access your resources/data. This normally brings into the fold another element of Serverless – an API Gateway. This is a service that provides the building blocks to create your own API with features that allow you to route specific endpoints to specific functions. They include support for various authentication solutions and usually feature documentation generation and development staging.
The API Gateway service can be found in each of the following cloud platforms:
- AWS – API Gateway
- Azure – API Management
In addition to using Serverless for API management and logic, you are not limited to using API Gateway/Management services if you have an existing solution already in place. You are able to execute functions (Lambda etc) through each platform’s own API’s and have the output of each execution returned to you. This allows you to then use the results within your existing API solution.
I personally have been a part of a few different projects involving elements of the Serverless model and I thought I would share some of these, as well as some frameworks to look out for that can make your Serverless adoption easier. Although there is a huge number of different use cases, I have picked a couple to talk about.
Governance – Security, Resource Cost & Analytics
Automating governance in the cloud is powerful and fast! Using Serverless to do this allows you to easily deploy solutions that fulfill governance needs with little effort. By using events in AWS to trigger your Serverless-driven API’s, you are able to scale the benefits they bring to many accounts, regions and users.
Examples of using Serverless for Governance are:
- Tag resources that do not match a resource tagging policy – Allowing resource usage to be grouped and tracked.
- Shut down instances running after a specific time – Keeping running costs down for non-essential resources
- Removing nodes from Configuration Management (Chef), Application Monitoring (New Relic) or Vulnerability/Anti-Virus systems (Nessus/Bitdefender) when terminated – Reducing management overhead for these services.
Amazon Alexa Skills
This is an area I have become particularly passionate and interested in lately and it’d be silly for me not to include this in this post.
Without going into too much detail, Amazon Alexa (Voice-controlled AI Speaker) is made up of Skills (Applications). The development workflow for these skills couldn’t be better suited for Serverless.
This is because all interactions with an Alexa Skill is based on making a request and receiving a response rather than having users constantly loading and viewing data as they would with, say, an iOS application. Interactions might include asking for the weather or booking an Uber. The user asks Alexa a question or to do something, and then waits for it to either tell the user it’s done or ask for further information to fulfil their request.
Using the Serverless model in this example means your Skill logic is able to be executed quickly and securely when needed – which could be millions of times a day or every so often – but you don’t have to worry about scaling the infrastructure that makes that logic work. This greatly reduces cost and simplifies the infrastructure overhead. What’s not to like?
A bunch of different frameworks have popped up over the last year, each boasting their own pros and cons and target uses. Below are some popular frameworks that you can have a look at using for your own Serverless projects
- Serverless – "Build auto-scaling, pay-per-execution, event-driven apps on AWS Lambda"
- Chalice – "Python Serverless Microframework for AWS"
- Zappa – "Serverless Python Web Services"
- Python-Alexa – Personal plug here – This framework is designed to be used with Alexa Skill development when done with AWS Lambda – It does all the heavy lifting and routing for you. All you have to do is write the logic code for what the skill does.
- and more – Check them out here.
Hopefully I have been able to shed some light on what Serverless is and at least given some examples of how you might want to use Serverless in your own projects. I see Serverless becoming increasingly more important as we go forward into 2017 and beyond. In Cloudreach alone, we have increased the amount of Serverless development within engagements and it has become the buzzword that everyone seems to be talking about. I think one area where Serverless will really shine is within the world of IoT – they almost seem made for each other!
This post avoids deeply technical information, instead intending to give some insight into higher level use cases and traction. If you’re interested in the more technical aspects, I would highly suggest checking out each Cloud Providers’ Serverless offering and have a play with them. Check out their documentation and see what you can do.
The frameworks I’ve mentioned and included in the linked GitHub page should also help to expand your usage in Serverless and hopefully allow you to see where it can fit in for you.
If you would like to look at some more in-depth articles relating to Lambda and how it works, I’d recommend having a look at some the links below: