AWS Lambda – Serverless Programming

Filed Under: AWS
Aws Lambda Serverless Programming

AWS Lambda is serverless programming. Serverless programming help to ease out the deployment on production. You just care about the code and rest will be handled by the cloud provider (AWS in our case).

AWS Lambda is one of the very popular technology among developers and technology solution providers on AWS Cloud. It’s an event-driven serverless computing platform that runs on AWS infrastructure. AWS Lambda service takes care of the computing machines that are required to run your application.

You might have started thinking about the AWS EC2 machines as they have the same capability. As compared to AWS EC2 machines, the AWS Lambda is the lightweight and on-demand solution. AWS EC2 requires expertise to work on and you must know how and when to scale your system. This is not the case with AWS Lambda, it scales automatically. All of the deployment work is gone if you are using AWS Lambda. Having said that you can virtually deploy any solution but there are many use cases for which AWS Lambda is the ideal solution.

To understand the concept of AWS Lambda, you must know about the serverless programming.

What is serverless programming?

The main aim of serverless programming is to simplify the deployment of the application. In serverless programming, cloud providers like AWS run the computing machine(servers). They manage the resource and machine allocation for your application.

Serverless programming is also known as Function-as-a-Service(FaaS). It basically runs your function and does not store any data. The complexity will be hidden for a developer such as scaling, resource management, and server capacity, etc.

What is AWS Lambda?

AWS lambda is an event-driven, serverless platform on Amazon Web Service (AWS). It can run virtually any type of application with no deployment and administration at all. AWS Lambda service will take care of the deployment and all administration related.

AWS Lambda runs the code when you actually use it so it reduces the overall cost drastically. AWS Lambda is the best solution for the event-based application. For Example, You want to resize the image and send an email whenever an image upload in AWS S3 bucket.

AWS took the Lambda service to the next level and integrated this with other services on AWS. You can trigger the Lambda functions in the response to certain events like the upload of an object in AWS S3, change in DynamoDB table, etc.

Features and Benefits of AWS Lambda

Automatic Scaling

Unlike other applications, AWS Lambda is designed to scale automatically. It scales on each trigger and runs your code in parallel. The performance of Lambda remains consistent and it can scale to any limit. As there is no limit to the number of request for your code.

Pay-per-use

Like any other service of AWS, Lambda billing model is also based on a pay-per-use model. You only pay for the requests that your lambda function has served. Lambda is highly cost-effective as it only runs to serve the request.

Serverless Architecture

You just write your code and upload it to the Lambda. AWS automatically will run your code on compute machines which are managed and provisioned by AWS itself. You are not required to provision the servers.

Fault tolerance Built-in

AWS lambda is designed to provide high availability and deal with partial failures. AWS Lambda has the fault tolerance built-in by maintaining the compute capacity across multiple availability zones. This is the primary reason for no maintenance window or downtime of the AWS Lambda?

Support for the Languages

AWS Lambda supports most of the popular programming languages like Java, Node.js, Python, and C#, etc. Many other languages support will come in the future.

Resource Controls

AWS Lambda also gives you the flexibility to manage resources like CPU, disk I/O and network bandwidth.

Popular Use Cases of AWS Lambda

Although, you can use the AWS Lambda for virtually any type of application and backend service. But this is important to know where the AWS Lambda fits well:

File processing in Real-time

File processing in realtime is the most popular use case of AWS Lambda. You can trigger Lambda functions in the response to file upload in Amazon S3. You can perform a variety of actions like resize images, create thumbnails, process log file, parse a file, etc.

Aws Realtime File Processing

Aws Realtime File Processing

Lambda as Backend

Another popular use case is Lambda as a backend service. You can create your services as Lambda functions and expose them to the API gateway. When a request will come to the API gateway, it will trigger the Lambda function to process the request.

See the below request flow of Lambda as a backend service:

Aws Lambda As Backend Service

Aws Lambda As Backend Service

AWS Lambda concepts

AWS lambda is based on function-as-as-service (FaaS). It lets you run your functions in a serverless environment. These functions are invoked in the response to a trigger called event. The Lambda function runs in isolation in response to an event.

Functions

The actual program or code that runs in AWS lambda is called function. Whenever an event occurs, Lambda passes the event to the function. Lambda processes the request and returns the response.

Runtimes

The runtime sits between your function and Lambda service. It passes the context information and responses between these two.

Lambda runtime allows your function to run in different languages. You just need to configure runtime based on the programming language that you have chosen to for Lambda function.

Layers

A layer is typically a ZIP archive that contains custom runtime, libraries, or any other dependencies. Layers allow using libraries in your functions without including them into packages.

You can create layers, or use layers published by AWS or other AWS customers.

Event Source

An event source is an AWS service that triggers your function to execute the code such as Amazon SNS

logs

AWS Lambda monitors your function automatically and sends the metrics to the CloudWatch. It also sends the log stream to CloudWatch that allow you to analyze the performance and flow of your lambda function.

Downstream Resource

A downstream resource is an AWS service that your Lambda function calls once it is triggered. It could be DynamoDB tables or Amazon S3 buckets, etc.

How AWS Lambda Works?

We will see several detailed examples in our next posts, let’s understand the basic flow of how the AWS Lambda works?

How Aws Lambda Works

How Aws Lambda Works

Upload/Write Code

There are two options to write a lambda function: 1) You can upload code from your local machine or repository. 2) Or you can use Lambda code editor to write the Lambda function.

Set Triggers

Once you have uploaded your code to AWS lambda then you can set up a trigger for other AWS services or endpoints to execute your Lambda function in response.

Run AWS Lambda

Lambda runs your code when triggered. An important point to notice is that it only runs the Lambda functions when triggered which makes it cost effective.

Pay time

You only pay for the time your Lambda was running to serve the request.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages