Launched in 2014, AWS Lambda is a serverless platform for Function as a Service. What does it mean? What are the main use cases? We will go into this in more detail in this article to explain the growing popularity of the service.
What is AWS Lambda?
The principle of AWS Lambda is basically very simple. It’s about providing functions (i.e. code) that respond to events without having to worry about the underlying infrastructure.
This means you don’t have to instantiate virtual machines (servers) that your application will run on. AWS takes care of the runtime environment for you. This is why it is also called a serverless service: even though there are of course servers hosting the application, they are completely abstract to the customer.
This has three main advantages:
- Reduce (or even eliminate) the time spent managing servers: Maintenance, updates, security patches, etc.
- Near infinite scalability: whether the function is run once a day or more than a million times, AWS adjusts the service accordingly without you having to worry about load balancing and auto scaling.
Load balancing distributes tasks (such as requests that need to be processed) across a number of servers instead of a single server to make the overall process more efficient.
Auto-scaling automatically adjusts computing capacity (i.e., the number of servers behind the load balancer) to match the load (which can be measured, for example, by the number of requests per minute). - Enable usage-based billing: Billing is per millisecond that the function is executed. If the function is not executed, you are simply not charged anything.
Since there is no server running all the time, the execution of functions must be triggered based on events. The sources of events can be very different: You can trigger the execution of a function when a file is uploaded to an S3 bucket, when a record is added to a DynamoDB table, in response to an HTTP request (via an integration with the API gateway service), or simply via scheduling (you can decide to call the function periodically, such as every minute or every hour).
A few case studies of AWS Lambda
The use cases for AWS Lambda capabilities are very diverse due to the large number of integrations with other services as source events. These include real-time data processing, file transformation, or even backends for web or mobile applications.
Creating image previews
One of the most commonly cited use case examples is the creation of thumbnails (preview images) when an image is uploaded to an S3 bucket (tray).
Suppose you’re developing an application that allows users to upload images and share them with others. You want the user to be able to upload photos in very high resolution, but you want to display low-resolution previews on the image gallery so that it loads quickly.
For this you can use S3 and AWS Lambda: An initial S3 tray can be used to store your users’ images. Using event notification, you can call a Lambda function every time a file is created in that compartment. This function can then generate a preview from the image and save it in a new compartment, which will then contain all the thumbnails :
Thanks to this serverless, event-driven architecture, your application automatically adapts to the number of downloads made by users.
One could easily imagine other similar applications:
- Generate an automatic transcription (via AWS Transcribe) when an audio file is downloaded.
- Real-time processing of data in a stream (Kinesis, Kafka).
Web and mobile application backends
Another common use of AWS Lambda features is the development of backends for mobile or web applications.
In fact, it is possible to use a Lambda function to process requests to API Gateway.
If you also use a database like DynamoDB, you can develop completely serverless backends (web, application, and database layers) that can scale perfectly depending on usage:Generate an automatic transcription (via AWS Transcribe) when an audio file is downloaded.
More information
As you’ve seen, AWS Lambda enables a wide variety of applications, which partly explains its growing popularity.
However, there are some limitations and complexities that come with using Lambda functions.
Among the limitations is the maximum execution time of a function, which is 15 minutes: lambda functions are not designed to perform long tasks. For example, if you want to do machine learning model training, AWS Lambda is probably not the right choice. Function memory is also limited to 10 GB and CPU power to 6 vCPUs.
Another complexity that can be cited is the difficulty of developing and deploying complex applications with Lambda.
But as your application code grows, going through the development environment built into the AWS console is less efficient or even impossible.
In this case, you need to develop your application locally on your computer and go through a repeatable process to package your code and deploy it to AWS, which can be complicated.
To simplify this task (and much more), one of the tools you can use is the Serverless framework, which lets you define your Lambda functions and associated code, their integrations, and other serverless resources (such as DynamoDB tables). Once you’ve defined your stack, you can easily deploy it to AWS using the framework.
If you want to learn more about AWS Lambda features and more generally about architecting IT systems in the AWS cloud, you can sign up for one of our training courses on this cloud provider.