Everything you want to know about Amazon’s first serverless computing service. A service that allows developers to use AWS infrastructure without having to look under the bonnet.
It’s been almost 5 years since AWS launched Lambda. The flexibility of this service has allowed it to find it’s way into every type of product. Signifying next level of developer interaction with the infrastructure, it is one of the most important additions offered by AWS.
From authentication into apps to serving as utilities and backends, there isn’t any domain left untouched by Lambda!
What is AWS Lambda?
AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of the Amazon Web Services. It is a compute service that runs code in response to events and automatically manages the compute resources required by that code.
In simple words, AWS Lambda, often referred to as “serverless” computing allows developers to think only about the code, and not have to worry about the layers below.
Over the past few years, people using “serverless” have found it’s the efficiency of utilization powerful.
Why run a server when you just need to do a few things every once in a while?
All the focus has to be put only on creating the business logic using functions and deploying them to the servers further letting the platform take care of operational aspects of the application, including scaling and high availability.
For example, if I need to send an email for every new order created, then it automatically invokes the email AWS Lambda function which further wraps up the task and goes on hibernation mode again until called upon!
Considering the compelling benefits, serverless computing and more fundamentally AWS Lambda has been hitting the prime time fairly quickly along with the boundless talk.
In this blog, we will discuss some of the prime use cases for AWS Lambda.
Support for native multi-programming languages.
AWS Lambda has been used to run Node.js, Python, Java, Go, C#, and even PowerShell.
There are also some additional opensource frameworks for more supported languages, rapid development, and deployments, like JAWS, Apex, Sparta and many others.
Even after a wide range of languages available, one should remember that AWS Lambdas are stateless. All they do is run your function once and then dispose of everything.
Amazon’s “Pay as you Go” service for AWS Lambda
While using AWS Lambda, one only pays for the compute time that has been billed based on used memory, the number of requests and execution duration rounded up to the nearest 100 milliseconds.
When your function is not being used, you pay a sum total of nothing!
This means that most people will see huge cost savings when compared with using Amazon EC2. Typically, Virtual Machines, in which end-users with the necessary admin permissions can install an additional operating system (or indeed several) on the same physical machine are subject to almost 90% under-utilization. With AWS Lambda, this approaches zero.
Think of a function that simply logs a simple Slack notification. With a minimum memory setting of 128 MB, this python function simply on receiving an AWS CloudWatch alert notifies the AWS SNS which further triggers the AWS Lambda function to send the notification via Slack. It runs in under 100 ms, so the execution time charged for each run is 100 ms. The estimated charges for 10 million executions of this AWS Lambda function per month is around $2.
This is another reason why SourceFuse has been using AWS Lambda as a part of most of our projects with the benefit of remitting only for long as we use them, and without requiring long-term contracts or complex licensing.
Another property of AWS Lambda is being event-driven, which means it reacts to specific kinds of input from users, whether it’s a click on a command button, a choice from a drop-down list, or other kinds of user events. This property makes it a unique, unlike the traditional ‘Platform as a service’ method.
It first needs to start the container while running the code at the same time. Additionally, the underlying container also needs to load the code before execution.
Performance of the function has always been a questionable aspect while using the service. Well for that, AWS launched AWS Lambda COLD Start and HOT Start which have significantly improved the performance issues. Once a cold start feature in Lambda is chosen, the AWS Lambda will remain instantiated for a while (5 minutes) allowing any other call not to have to wait for this initialization to be done each time. Calls made during this period are called “warm call”, which means that the code is loaded into memory and ready to be executed when the AWS Lambda is called one or several times.
No administration of infrastructure needed.
AWS Lambda function provides the freedom to build new infrastructure without having to add resources to it.
Seems pretty much useful for the managers!
AWS Lambda provides a platform where one can enrich the already existing infrastructure or deploy a new service in a microservices architecture. And just to bring to your notice, there are some services on AWS where AWS Lambda s are the only real way to perform certain tasks like logging Cognito login requests. For functional programming lovers, the fact that they can concentrate more on developing their code rather than managing their servers.
The fortune of practising serverless computing
Serverless architecture is a style of programming for cloud platforms that are changing the way applications are built, deployed, and – ultimately – consumed.
A popular approach to running “serverless” web applications is to implement the application functionality as one or more functions in AWS Lambda and then expose these for public consumption using Amazon API Gateway.
Another major cause is when we can use AWS Lambda functions on AWS S3 event triggers.
Here we create an IAM role which AWS Lambda will use to work with AWS S3 and to write logs to AWS CloudWatch. AWS Lambda will write the function activity to CloudWatch.
So, when a new file is uploaded to the S3 bucket, that has the subscribed event, this should automatically kick off the AWS Lambda function. As for AWS Lambda, API Gateway and S3, you pay only after the traffic is incurred and the only fixed cost will be running the database service.
Scale instantly with AWS Lambda
AWS Lambda provides a feature to scale instantaneously to a large number of parallel code execution processes. This is the “Number of concurrent requests” feature.
The fact that the needless function stops as soon as the code is executed helps minimize the overall cost.
Due to its scalability, one can easily place AWS Lambda in between services to transform and load data as and when required.
The ease of doing everyday tasks
A great thing about the AWS Lambda function is that it allows one to use any of AWS’s monitoring and management service, like Cloudwatch to search for specific moments or log files. Custom notification hooks to Slack can be easily implemented by calling their API endpoint within AWS Lambda.
Frequently occurring events like checking for idle resources, creating backup & generating reports can be easily implemented in no time using the AWS Lambda function.
Running your AWS Lambda ’s locally
AWS Lambda is built on the FireCracker framework. When AWS Lambda was introduced, the whole package had to be uploaded even for testing purpose which used to cause a log in performance.
Now AWS Lambda recently brought AWS SAM(Serverless Application Model) CLI which has become the core of launching serverless application locally.
Using SAM, one can create a CloudFormation template just to define the application. The template here should be written in YAML to make it as clean and less cluttered as possible.
Then by calling the AWS Lambda locally using the SAM CLI, you’ll pass to the AWS Lambda either through the output of a SAM CLI “generate-event” command or by passing a JSON file with static data. SAM requires Python, Docker, and AWS CLI.
Let’s get to the part where SourceFuse has used AWS Lambda
App for US based Transport Industry:
The App presents a new option for non-emergent ambulatory transportation through a proprietary, web-based application designed to provide a seamless experience for claims staff, nurses and injured workers.
We used AWS Lambda for majorly three tasks:
- When a ride is booked or after a ride is successfully completed, it sends a trigger to AWS Lambda which is then responsible for collecting the screenshots of the route of the ride, pretty much similar to uber invoices. Then it saves it in an S3 bucket with respective thumbnails.
- SourceFuse took the advantage of AWS Lambda is an “event-driven” function for an entire module called Group Health which checks availability for forthcoming rides. Here AWS Lambda is responsible for sending alerts along the whole process of booking a ride and validating if the ride is even possible or not in that area. This AWS Lambda then triggers AWS SQS which sends alerts various alerts like “No driver available” or “You’re ride is here!”.
The foremost benefit of using AWS Lambda here was that the infrastructure does not need to be up the whole time, which remarkably saves costs.
- Lambda has also been used for scheduling jobs at different intervals for the purpose of creating statistical reports for management purposes.
Aperio is a healthcare logistics application that enables hospitals and clinics to update and maintain their employee health records.
The project used AWS Lambda functions to keep track of its employee health record and content management modules by keeping their data in sync.
Let’s say there was a depression patient that had been treated in a hospital. Initially, all his entry will be kept in the EHR system. After some time the employee has been released but with certain treatment that would allow him to be fully recovered. Now for information on this, the content management system needs to be updated with all the details of the person so that he updated with the correct course and is updated about his medicines on a timely basis. Based on these logics, courses for the patients are assigned and all data are synced using time and AWS Lambda s’ with AWS SQS service.
AWS Lambda function is also used in the backend to update all the daily tasks assigned to the employees like daily schedules and emails. This is done using an AWS CloudWatch event, that is defined in AWS Lambda.