Once upon a time, the smallest unit of compute you could use was a physical server, Then came virtualization and all that changed. Multiple virtual machines can run on a single physical server, which allows better server utilization. This was also one of the major drivers to reduce cost. And then came containers. A container is an even smaller unit of compute, enabling you to split your virtual machines even further to achieve even higher utilization.
And then AWS caused another upheaval.
You might already know that Lambda is the 11th letter of the Greek alphabet. However, Lambda is also one of the many services you can use in AWS. AWS Lambda is a compute service that lets you do exactly what you want with your application – without the need to maintain a compute instance underneath it.
You might ask yourself, “How can I run my application without actually provisioning the underlying compute resource? How is that even possible?” We are all accustomed to a mindset whereby we have to provision an underlying operating system, making this concept a bit hard to grasp.
The need for compute resources to run your application still exists, especially on your premises but with an advanced public service such AWS Lambda you no longer have to worry about provisioning and maintaining those resources yourself – AWS takes care of all that for you.
AWS provides the API for you to upload your code – which can be either C#, node.js, java or Python – and sets an event that will trigger the function. The code itself is then run on a server in the cloud, and you are billed only for the duration that your code ran.
Example Use Cases
The number of possibilities and options is practically endless. Here are a few examples.
1. Processing Video
You have an S3 bucket where you store video files. Until now, you had an instance that would poll the bucket on a regular basis. When it recognized a new file had been uploaded, it would download the file, run a set of commands to manipulate the video (create different bitrates or copies of the file, etc.), and then push that file to your origin server.
That means you had an instance, which was costing you money, sitting idle for a good part of the day – doing nothing – because no new video files were uploaded. And still you were using compute resources 24/7.
With Lambda, you can upload your script (Python, for example) and configure the code to trigger an event when a new file is uploaded to the bucket. As a result of that event, the file is processed and pushed to your origin server. That’s it.
2. Automated File Synchronization
You have a repository that needs to be synchronized on a regular basis to a number of locations several times a day.
Most people would not use a dedicated instance for things like this, instead they would double (or triple) up on another instance and just assign this task to it. But that might not always be a great option, depending on security policies or contention for resources at certain times of day.
Instead of keeping an instance up and running 24/7, chewing away at your budget every month, you can use a Lambda function that will be triggered by a scheduled event, run your synchronization job, and then just go away until the next cycle that it needs to run.
3. Data Transformation
Your application produces output (such as a file or a database) on a regular basis. You need to take that information and convert it into another format, for example, from a flat file into a json file, or from a json file into a database.
Until now, you would have used a full instance to perform these conversions, most probably in some kind of batch mode. With Lambda, you can create a trigger so that when a new line (or batch of lines) is written to your database, your Lambda function transforms that data from one format to another – without you having to maintain another instance to continuously poll.
4. Security Alerts
Monitoring your logs and keeping an audit trail is imperative to your overall cloud strategy, and you should be aware of any security breaches in your cloud infrastructure.
You can write a Lambda function/script to send you an alert on a specific event from your Cloudwatch/CloudTrail AWS activity logs to your designated on-call staff (by email or using a collaboration tool such as Slack or Hipchat), and in the event of a severe breach, even write something that could actually call you on your phone.
Lambda Benefits & Limitations
There are a number of reasons why using Lambda makes sense.
- A good part of our scheduled operations and services only run during parts of the day. There are always periods of time where these instances sit idle. And during those times you pay for your compute resources.
The billing period on a Lambda function is in the milliseconds, so it could significantly reduce costs.
- Operating systems and instances come with operational overhead. You need to manage these instances, patch them, monitor them – all with a cost attached. With Lambda, you don’t need to worry about the underlying instances because they are so short lived, and are re-provisioned each and every time a function runs.
On the other hand hand, Lambda is not suitable for all use cases; it does have its limitations.
- The application size and resources it can consume are limited and not all applications are suitable to run as Lambda functions.
- Processes that take an extended period of time to complete are also not suitable to run as Lambda functions. If you have a complex function that does 15 different things, it might be better to split these up into multiple functions or create a service out of them.
[boxRead more about 7 AWS Lambda Alternatives[/box]
AWS Lambda provides you with even more granular control over the services you wish to provide to your customers, assuming that they can actually be split out into actual tasks that can be run as functions inside Lambda. It would be well worth your while to understand the capabilities of this service, which can drastically reduce the cost of your cloud operations while allowing you to scale your applications to levels not previously possible, and evaluate how this fits into your overall strategy to provide value to your customers.