Open In App

AWS Lambda

Last Updated : 24 Oct, 2025
Comments
Improve
Suggest changes
6 Likes
Like
Report

Running code on traditional servers can be expensive and inefficient. For example, if you need to resize an image every time a user uploads one, you'd have to set up a server, keep it running all the time, apply updates, and monitor it even if the task only happens occasionally.

AWS Lambda solves this problem. It’s a cloud service that runs your code only when needed. You upload your code, and AWS takes care of everything else like scaling, security, and availability.

The two key terms to understand are:

  • Serverless: This doesn't mean there are no servers; it means you don't have to manage them. AWS handles all the provisioning, patching, scaling, and maintenance.
  • Event-Driven: Lambda functions don't run all the time. They sit idle until they are triggered by an event.

The Core of Lambda: The Event-Driven Model

At its heart, every serverless application built with Lambda follows a simple, powerful model consisting of three parts:

  1. Event Source (The Trigger): This is what initiates the execution of your function. It can be almost anything in the AWS ecosystem.
  2. The Lambda Function (Your Code): This is the code you write to process the event.
  3. Downstream Services: These are the services your function interacts with after it has processed the event.

For example: A new image uploaded to an Amazon S3 bucket (Event Source) triggers a Lambda Function (Your Code) that resizes the image and saves the new version back to another S3 bucket (Downstream Service)

AWS (Amazon Web Services) Lambda

Key Features and Benefits

  • No Servers to Manage (Serverless): This is the core benefit. You can focus entirely on writing business logic, not on managing infrastructure. AWS handles the rest.
  • Pay-Per-Execution Pricing: You are charged only for what you use. Pricing is based on the number of requests for your function and the duration (in milliseconds) it takes for your code to execute. There is no charge when your code is not running.
  • Continuous, Automatic Scaling: Lambda automatically scales your application in response to every trigger. It can scale from a handful of requests per day to thousands per second without any configuration changes.
  • Tight Integration with the AWS Ecosystem: Lambda is the glue that can connect dozens of AWS services. You can trigger functions from services like S3, API Gateway, DynamoDB, SQS, Kinesis, and more.
  • Broad Language Support: You can write Lambda functions in your favorite language. Supported runtimes include Python, Node.js, Java, Go, Ruby, .NET, and you can even bring your own custom runtime.

Example:

  1. Process data from Amazon S3 buckets.
  2. Respond to HTTP requests.
  3. Build serverless applications.

The Anatomy of a Lambda Function

When you write a Lambda function, you're primarily concerned with three components:

  1. The Handler Function: This is the specific function in your code that Lambda will execute when it's invoked. In Python, it's typically named lambda_handler.
  2. The event Object: When your function is triggered, Lambda passes an event object to your handler. This object contains all the information about the triggering event. For an S3 trigger, it would include the bucket name and the key of the file that was uploaded.
  3. The context Object: This object provides runtime information about the invocation, function, and execution environment, such as the Request ID, log group name, and how much time is remaining before the function times out.
  4. The Execution Role: Every Lambda function has an IAM Role associated with it. This role defines the permissions your function has to interact with other AWS services (e.g., permission to read from an S3 bucket or write logs to Amazon CloudWatch).

Use Cases of AWS Lambda Functions

You can trigger the lambda in so many ways some of which are mentioned below.

  1. File Processing: AWS lambda can be triggered by using simple storage services (S3). Whenever files are added to the S3 service Lambda data processing will be triggered.
  2. Web Applications: You can combine both web applications and AWS lambda which will scale up and down automatically based on the incoming traffic.
  3. IoT (Internet of Things) applications: You can trigger the AWS lambda based on certain conditions while processing the data from the device which are connected to the IOT applications. It will analyze the data which are received from the IOT application.
  4. Stream Processing: Lambda functions can be integrated with the Amazon kinesis to process real-time streaming data for application tracking, log filtering, and so on.

AWS lambda will help you to focus more on your code than the underlying infrastructure. The infrastructure maintenance in AWS was taken care of by AWS lambda.

Working of AWS Lambda Functions

Start off by uploading the code to AWS Lambda. From there, set up the code to trigger from other AWS services, HTTP endpoints, or mobile apps. AWS Lambda will only run the code when it's triggered and will also only use the computing resources needed to run it. The user has to pay only for the compute time used.

AWS (Amazon Web Services) Lambda

Getting Started With AWS Lambda Function

The following are the steps mentioned below to create your own customized AWS lambda functions by using the AWS console. Create an AWS account.

Steps for Creating AWS Lambda Functions Using AWS Console

Step 1: Log in to your AWS console and search for Lambda. As shown in the following image.

Lambda

Step 2: Click on Create function.

Create Function

Step 3: Here we are going to use a sample hello world program by using Author from scratch and configure the details according to your requirement.

Configure the function

Step 4: Successfully our function is created.

Function Created

Pricing of AWS Lambda Function

AWS lambda pricing is based on the no.of requests made to your function and the time it has taken to execute the function. The following are the pricing factors to be considered for AWS Lambda. As previously mentioned, with AWS Lambda user only pays for what he uses, factoring in the number of requests and duration of the execution of the code. No charges are taken for creating lambda functions. Lambda considers a request to be each time it starts executing in response to a trigger such as an event notification or an invocation volume. The duration of the code is calculated from the moment the code begins executing until it returns or is terminated. If one is unsure about whether AWS Lambda is the right choice or not, there is a free tier option available to try. This option includes 1M free requests per month and 400,000 GB-seconds of compute time per month.

  1. Requests: AWS lambda charges are made up of the no.of requests made to your AWS lambda function. Each request will be counted individually based on the time duration also aws lambda will calculate all the requests made per month. The pricing will be varied from the different regions and the total no.of requests made for your function.
  2. Duration: AWS lambda will be charged based on the duration of time your code started executing and till the time it is terminated. And also while executing the AWS lambda you should allocate some memory to your function this factor is also counted while billing.
  3. Free requests: You have one million free requests per month which is free for all users and when coming to the duration you have 400,000 GB-seconds of compute time per month.

Common Use Cases

  • Real-time File Processing: Trigger a function to resize images, transcode videos, or perform OCR on documents as they are uploaded to S3.
  • Serverless Web Backends: Use Amazon API Gateway to create a REST API that triggers Lambda functions to handle HTTP requests for your web or mobile application.
  • Data Processing (ETL): Process and transform real-time data from streams like Amazon Kinesis or DynamoDB Streams.
  • Automation / "Cron in the Cloud": Schedule functions to run at regular intervals using Amazon EventBridge to perform tasks like generating daily reports, cleaning up resources, or running backups.

Monitoring Your AWS Lambda Usage

Monitoring your AWS Lambda usage is crucial for understanding and controlling costs, especially as your workloads scale beyond the AWS Free Tier limits. Here are some ways to effectively track and manage Lambda usage:

  • CloudWatch Metrics: Track invocation counts, execution duration, error rates and memory use. You can set alarms to alert you when usage exceeds specific thresholds​.
  • Cost Explorer: Visualize and analyze your spending patterns by breaking down Lambda expenses. Set budgets and alerts to manage monthly costs effectively​.
  • Usage Reports: Access detailed reports in the AWS Billing Console for monthly usage across AWS services, helpful for teams needing cost allocation across functions​.
  • Third-Party Tools: Use tools like Datadog, Lumigo and New Relic for advanced monitoring and insights, allowing for more detailed performance tracking and cost optimization​.

Explore