Cloud & Infrastructure

Introduction to AWS Lambda

AWS Lambda

Serverless Computing has garnered significant traction in recent times as a way to run workloads in the cloud. The premise of Serverless Computing is to allow developers to focus on the code, deploy code as functions and deploy their code without worrying about provisioning servers. The infrastructure vendor takes care of running the functions at scale and low cost, thereby giving tremendous agility to organizations looking at employing Microservices-based architecture in their applications.

Amazon Web Services was the first of the blocks and they announces their Serverless offering, AWS Lambda around end 2014. It has seen significant traction and other cloud infrastructure vendors like Google and Microsoft have had to announce their offerings too. Google announced Google Cloud Functions towards late 2015 and their annual developer conference, Microsoft announced a similar offering named Azure Functions. The offerings differ in terms of pricing, event sources, triggers and languages supported.

AWS Lambda is the leading Serverless computing platform by far, not just by its early announcement but its deep integration with various AWS Services that makes it a good fit for current AWS users to start evaluating it at the earliest. To better understand AWS Lambda, it is important to fundamentally look at a function as the basic compute unit. A function is the piece of code that you develop and deploy as a single unit i.e. the function. By design, it is important that you consider the function via the following design principles:

  • It should be a single-purpose function with a well-defined functionality.
  • It should be stateless
  • How the function should be triggered : via on-demand direct invocation or via an event

Let us look at each of the above points in brief now. To write the function, AWS Lambda supports the following languages: Java, Python and Node.js though there are reports of developers packaging functionality written in other languages and then invoking it via the process execution support available in the supported languages. The code can then either be written in the online editor or packaged as a ZIP file along with other dependencies. You can then deploy the function and you are all set.

A high level template for a function written in Node.js for AWS Lambda is shown below:

AWS Lambda is strong in its support for various other AWS Services and this brings in the discussion of how we can invoke our functions. If you want to directly invoke the AWS Lambda functions, then it is recommended that you place these functions behind an API Gateway. An API Gateway provides authentication/authorization services and provides other orthogonal functions like logging, throttling, rate limiting and more. The other way is asynchronous in nature and this is where other AWS Services like S3, DynamoDB, SNS and more come in. For e.g. you could have AWS Lambda invoke your function when someone uploads a file in S3 or when a DynamoDB table row changes, etc. Similarly, you can invoke other services as part of the AWS Lambda. This close integration both direct and asynchronous is a key feature that allows you to design an application that is an orchestration of multiple services.

The pricing of AWS Lambda is interesting. It is based on the number of request calls for your function and the time that it executes. There is a free tier that is supported beyond which the standard pricing kicks in. It is extremely cost effective looking at the the minimal cost that it charges for thousands of requests.

The AWS Lambda page provides good inputs on multiple domains that are well suited to using Serverless computing. Some of the area include ETL, Mobile Backends, APIs, IoT and other applications. Keep in mind that if real time is a required functionality in your applications, then AWS Lambda might not be a good fit for those kinds of applications.

Serverless Computing is definitely the next wave of how developers go about developing and deploying their code. We have seen a transition from running our Apps on Servers, then containerizing them and finally Functions. It is recommended that you start small with this approach and gradually build up the entire application, since not every functionality or module might be a good fit for Serverless Computing. AWS Lambda is definitely the leading platform in this space and if you are already invested in this space, you will find that it integrates with multiple other AWS Services. The other vendors are working hard to make their offerings match up to AWS Lambda and we should see a lot of movement in this space in the next 6-12 months.