What is AWS Lambda?

Overview

In AWS, AWS Lambda is a technology that helps you execute your code without managing or configuring a server. With AWS Lambda, you write code in any language that runs when there is a certain event you have enabled in any of your Amazon services. These codes are also known as serverless or Lambda functions.

Common events that can trigger a serverless function include an image or file upload, inserting data to a database, downloading a file from a web application, etc. When any of these events are triggered, the serverless function or Lambda function executes.

How AWS Lambda works

Lambda is a way to write code that runs when an event is triggered on any of your AWS services.

For example, you can write a function known as a serverless function that will be triggered when you upload a file to your Amazon S3 Bucket. The code might be to crop or resize the image, so when the image is uploaded through your web app to S3, the serverless function (your AWS Lambda) runs instantly.

Below are the 3 steps to understand how serverless or Lambda functions work.

1. Set up your service

Your service is what triggers the Lambda function. Your service is any Amazon service of yours, such as your S3 bucket, your EC2 instance, etc. These services can require API calls to run them or be manual, depending on what you want and how you want the service. Whatever you do on this service triggers your function.

For example, your S3 bucket can be set to trigger your instance when there is a file deletion.

Fig 1: Set up your Amazon Services

2. Set up your Lambda function

Your Lambda function can be a plain code written by you, an already created template, or a container image. Whichever way you want it, you have to then attach the service that triggers this function.

The trigger is the event that takes place for a serverless function to execute. An example of a trigger is a file upload or API request to post a resource or object to the S3 bucket.

Fig 2: A Serverless function triggered when file is uploaded

3. View invocations

You can use the CloudWatch management console to view the invocations of your serverless functions. The console shows you the metrics of your function invocation.

Free Resources