Lambda Functions

Get an overview of the Lambda function and its suitability for applications that don’t require continuous availability.

AWS Lambda allows us to run code without managing servers. It lets us execute functions in response to events, such as changes in data, user actions, or time triggers. We pay only for the compute time our code consumes, making it cost-effective and scalable. It supports various programming languages, making it accessible to various applications and developers. AWS Lambda is amongst the core serverless computing services offered by AWS.

Press + to interact

Let’s start this lesson with a brief introduction to serverless computing.

What is serverless computing?

Serverless computing is a computing model where developers can build and run applications without managing or worrying about the underlying servers. In contrast to this, EC2 provides virtual servers that must be provisioned, managed, and scaled manually, and users pay for the server’s uptime, regardless of the workload. Lambda is ideal for event-driven, short-lived tasks, while EC2 offers more control but requires more operational overhead.

Serverless architecture allows us to focus on the functions rather than spending time managing a server. Functions are stateless and event-driven, executed when the function is triggered. This saves us a lot of running costs for the servers since functions are short-lived and are billed on pay-per-execution. The diagram below highlights a serverless architecture.

Press + to interact
Serverless architecture
Serverless architecture

AWS Lambda in action

AWS Lambda allows us to run code without managing servers. Lambda is an ideal computing service for applications that don’t require continuous availability, application scenarios that require rapid scaling, and where the flow of an application is based on triggering events. When working with Lambda, we are only responsible for the code. Lambda provisions the compute resource to offer a balanced memory, CPU, network and other resources. As Lambda itself manages the infrastructure, we can not customize compute instances or operating systems provided on runtimes.

Lambda runtimes offer a language-specific environment to execute the function code. Each programming language has a runtime with a unique identifier, such as nodejs20.x or python3.12. Keeping the Lambda code updated to the latest runtime is important as AWS Lambda does not offer backward compatibility between major versions.

Example: Adding watermarks to images

Let’s take an example of a web application that adds watermarks to images, ensuring they are not misused. The static web pages of the application are hosted on the S3 bucket. Whenever an image is uploaded, the application processes the image and uploads it back to the S3 bucket, making it available for users.

Press + to interact
Lambda in action
Lambda in action

This operation can be efficiently handled using a Lambda function. Since the compute resource is only required when a new image is uploaded and does not require a dedicated compute resource running 24/7. The Lambda function executes the code when the image is uploaded to the S3 bucket.


Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy