Please use the menu below to navigate the article sections:
When it comes to compute options in AWS – the choices are seemingly endless. AWS Lambda is one of the many options available. The distinction of which compute service best suits your needs is however dependent on your use cases and in order to make an informed decision, there are a few things to consider.
When you are building and running your workloads on AWS, and it comes to choosing how your compute requirements are met, you might want to provision highly specific and finely tuned instances of compute, with specific RAM, storage, networking and sometimes even using specific hardware.
This might be for certain reasons like compliance, or compatibility, and for these use cases a service like EC2 will suit you perfectly. In this model as I described above, you configure the underlying servers and infrastructure.
This is the traditional way to choose your compute requirements not only on premises – but also in cloud environments.
If you require a non-specific amount of compute and you don’t want to maintain servers, and if you want a large degree of scalability and flexibility – a serverless deployment might be for you.
What is a Serverless Application?
Serverless takes all of this heavy lifting off of your hands, and makes your job much easier, allowing you to to focus on your business cases – and get the highly scalable and durable compute needed for your use case.
Whilst all serverless services do actually use servers and hardware at one level, the user does not have to configure any kind of computing environment, or any parameters to do with infrastructure. The code is run by some hidden servers, and it just works!
The lack of administration and upkeep of the hardware allows you to be very flexible and purposeful with your use of code in the cloud, and in reality serverless is very much a concept that doesn’t exist without the cloud.
Lambda is AWS’s principle serverless compute service, and it allows you to run your code in the cloud in a simple and highly scalable way without having to configure any infrastructure. You upload your code, and hook it up to other AWS services and it just works. No fiddling with servers and stressing about what to deploy and wondering if it will scale to meet your demands.
Lambda quickly and directly allocates compute for your code and runs it based on an incoming event. An event is a trigger which you can select as a starting point for your code to run. You can set up your code to automatically trigger from over 200 AWS services and various third party SaaS applications, as well as from other Lambda functions also.
Because you only pay for what you use, Lambda is billed at the millisecond level, allowing only exactly what you use to be billed (outside of a generous free tier limit).
How does AWS Lambda work?
First, you have to start by writing your Lambda function. What is an AWS lambda function? It’s simply a deployment of your code in Lambda. You can write your code in any of these supported programming languages:
Once written, you upload your code to AWS Lambda (or you can write it directly in the text editor) and then, you set up your code to run in response to a trigger from other AWS Services, HTTP Activity, endpoint activity, etc. and then you wait for triggers.
Your code will run, and you will only pay for the milliseconds of code you ran.
What are some Use Cases for AWS Lambda?
The first way you could utilize Lambda is to execute code in response to triggers such as changes in data, shifts in system state, or actions by users. Lambda can be directly triggered by AWS services such as S3, DynamoDB, Kinesis, SNS, and CloudWatch, can connect to existing EFS file systems, or it can be orchestrated into workflows using something called Step Functions. This allows you to build a variety of real-time serverless data processing systems, which would only be running when you need them – thus saving on compute costs.
Video / File Processing
You can for example use Amazon S3 to trigger a Lambda function to start processing data immediately after it has been uploaded by a user as part of your application. You could also attach an existing Amazon EFS file system directly, which enables massive shared access for super large-scale file processing. For example, you can use Lambda to create thumbnail images, transcode videos, index files, process logs, validate content, and aggregate and filter data in real-time.
The common denominator for these use cases is that the processing is not continuous, and is often completed in a few milliseconds. It is here where Lambda demonstrates its powerful service, as you can avoid having servers running constantly when they are not needed. With serverless, you can make best use of the servers by only running them (and paying for them) when you need to.
It is also important to note that the maximum runtime for Lambda functions is 15 minutes, but if you need anything longer than that, whilst still keeping your compute serverless, AWS Fargate is your choice of service.
The uses for Lambda are limitless – and if you need cheap serverless compute for any part of your AWS infrastructure, think AWS Lambda.
How does pricing work for Lambda?
You can take advantage of the free tier with Lambda, as AWS Lambda’s free usage tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month. Therefore if you are a startup, or if you are a hobbyist who is running small workloads on AWS Lambda, your compute costs for the first year could be zero.
As the free tier doesn’t last forever, it is important to take note of the fees for lambda outside of the free tier.
Lambda is charged in two ways – in number of requests and in duration of request. You’ll find the prices below:
- Requests– $0.20 per 1M requests
- Duration – $0.0000166667 for every GB-second
In conclusion, serverless can be a powerful tool to lower cost, ensure scalability and to ensure your applications are powered sufficiently.
Get Hands-On with AWS Lambda!
Check out this AWS Lambda tutorial to learn how to create a serverless function.
Or you may be keen to learn how to create a CV/resume website using AWS S3.
Looking for practical experience with AWS? Get hands-on with Amazon S3 challenge labs in a sandbox environment.