AWS LAMBDA – Here’s Everything You Need to Know!

What is Serverless?

To understand what AWS Lambda is, we have to first understand all about serverless architecture. The serverless architecture is a way to build and run applications and services without having to manage infrastructure. Your application still runs on servers. When you run a serverless application, you get the benefit of not worrying about OS setup, patching, or scaling of servers that you would have to consider when you run your application on a physical server.

Serverless applications or platforms have four characteristics:

  • No server management
  • Flexible scaling
  • No idle capacity
  • High availability

Lamda Intro

Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availability compute infrastructure and performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring, and logging. With Lambda, you can run code for virtually any type of application or back-end service. All you need to do is supply your code in one of the languages that Lambda supports.

Why AWS Lambda

Serverless Architecture:

AWS manages the entire infrastructure layer of AWS Lambda. Customers don’t get much visibility into how the system operates, but they also don’t need to worry about updating the underlying machines, avoiding network contention, and so on—AWS takes care of this itself.

Code freely:

And with the service fully managed, using AWS Lambda can save you time on operational tasks. When there is no infrastructure to maintain, you can spend more time working on the application code—even though this also means you give up the flexibility of operating your own infrastructure.

Pay-as-you-go:

Lambda runs your function only when needed and scales automatically. From a few requests per day to thousands per second, you pay only for the compute time that you consume—there is no charge when your code is not running.

Monitor your performance:

AWS Lambda monitors functions on your behalf and sends metrics to Amazon CloudWatch. The Lambda console creates monitoring graphs for these metrics and shows them on the Monitoring page for each Lambda function.

How Lambda Works?

  • Firstly, upload your code to ‘Lambda’ in one or more lambda functions.
  • AWS Lambda will then execute the code on your behalf
  • After the code gets invoked, lambda automatically takes care of provisioning and managing the required servers.

Features

Fig – 1-1 Lambda Concepts

Function – A script or program that runs in AWS Lambda. Lambda passes invocation events to your function. The function processes an event and returns a response.

Code – the logic you use in the lambda function

Runtime – lambda runtime executes your function, majorly supporting below runtimes

Fig.1-2 runtime supported in lambda

Handler – the method your runtime executes when your function gets invoked

Tags – Key-value pairs your function gets attached with

Description – describing the function

Timeout – the maximum time a function is allowed to execute

Layers – Lambda layers are a distribution mechanism for libraries, custom
runtimes, and other function dependencies.

Log Streams – Lambda automatically monitors your function invocations and report metrics to CloudWatch.

  • Invocations – The number of times the function got invoked.
  • Duration – The average, minimum, and maximum execution times.
  • Error count and success rate (%) – The number of errors and the percentage of executions that got completed without error.
Fig.1-3 cloudwatch metrics

Limitations in Lambda?

  • The maximum disk space provided is 512 MB for the runtime environment.
  • Its memory volume varies between 128 to 3008 MB to the function during execution.
  • The function timeout gets set to only 900 seconds (15 Minutes). Default is 3 seconds.
  • We can only use the available languages in the lambda editor.

Demo

In this demo, we are going to create a sample test function in which S3 will act as a trigger. When anyone uploads a new object to the s3 bucket, then lambda gets triggered, and we can see the invocations in the CoudWatch.

Step 1: Create a lambda function and select Author from scratch to upload your code.

fig-1 create the lambda function

Step 2 Select the AWS S3 as a trigger and do the configuration

fig 2-1 s3 as a trigger
fig 2-2 trigger configuration

Step 3 In the Code source block, upload your code or write your own code.

fig 3 upload your code

Step 4 Now upload the object in the S3 bucket, so Lambda gets triggered

fig 4 upload object to s3 bucket

Step 5 Now go to the monitor section of the Lambda Function Console, you can view the Invocations

fig 5 Invocations

Conclusions

Building serverless applications on AWS relieves you of the responsibilities and constraints that servers introduce. Using AWS Lambda as your serverless logic layer enables you to build faster and lets you focus your development efforts on what differentiates your application. Alongside Lambda, AWS provides additional serverless capabilities to build robust, performant, event-driven, reliable, secure, and cost-effective applications. With AWS Lambda, you can stay busy with your development work without worrying about managing the servers and infrastructure.

But with AWS lambda, you need to go with certain limitations that your code can run a maximum of 15 mins only, and we cannot select AWS resources like the types of EC2 instances. Lambda provides resources based on our workload.  AWS Lambda is used only for running and executing our back-end code.

Let us know in the comment section about your experience with the AWS Lambda & its components and & also if you want more blogs regarding AWS services.

Blog Pundit: Bhupender Rawat and Adeel Ahmad

Opstree is an End to End DevOps solution provider

Connect Us

Leave a Reply