What is an AWS Lambda Function?

In this article, we will cover the basics of a Lambda function and its functionality in our every day digital lives.

AWS Lambda, as we already know, is a compute service that allows you to run code without managing servers. AWS Lambda runs the code when it is needed, and it is automatically scaled. The code you execute on AWS Lambda is called Lambda function, and it can be considered, for better understanding, as a formula in a spreadsheet. As you need to make formulas, so it could automatically calculate any data you enter, functions are somewhat similar.

The Basics

Creating simple functions via the Lambda web console is quite easy. Functions allow your code to run smoothly in performing smaller automated tasks. The function is ready to run as soon as it has been triggered. The Lambda function includes your code along with associated configuration information. Lambda functions have nothing to do with the underlying infrastructure. Therefore, Lambda can execute as many copies of the function as needed so it can be scaled to comply with the rate of the incoming events.

When your code is uploaded to AWS Lambda, your function is commonly associated with some specific AWS resources like an Amazon S3 bucket, an Amazon DynamoDB table, Amazon SNS notifications, or Amazon Kinesis streams. After associating your function with AWS resources, when the resource has changed, Lambda will execute your function and manage the compute resources to achieve success with the incoming requests.

Building Lambda Functions

After uploading your application code in the form of one or even several AWS Lambda functions to AWS Lambda, AWS Lambda will execute the code for you. AWS Lambda takes care of managing the servers to run the code when invoked. The lifecycle of an AWS Lambda-based application includes several sections.

  • Authoring code for your Lambda function in the languages supported by AWS Lambda. The supported languages are Node.js, Java, C#, Python, and Go. These languages use specific tools for authoring code. Some of them are AWS Lambda console, Eclipse IDE, etc.
  • Deploying code and creating a Lambda function requires you first to package your code and dependencies in a deployment package to be able to develop a Lambda function. After doing so, you need to upload the deployment package to AWS Lambda, so it will allow you to create Lambda function. Organizing your code and dependencies in specific ways is the first step towards building the deployment package. Deployment package instructions may vary depending on the language you have chosen to author the code.
  • Uploading a deployment package is allowed by AWS Lambda’s CreateFunction operation which is used for creating a Lambda function. You can choose between AWS Lambda console, AWS CLI, and AWS SDKs to create a lambda function. Providing configuration information after establishing the lambda function including the compute requirements is submitted to your deployment package.
  • Testing Lambda functions can be done by following one of the methods like testing your lambda function in the console or using the AWS CLI or even check it locally using the AWS SAM CLI.
  • Monitoring of lambda functions becomes automatic after your it is in production while reporting metrics is done through Amazon CloudWatch. This is the main pain-point of lambda functions. Take a look at our site to get better insight into your Lambda functions.
  • Lambda itself assists in troubleshooting failures in a function. Lambda logs all of the requests that are handled by your function and it also automatically stores all the logs generated by your code in Amazon CloudWatch Logs.

Configuring Lambda Functions

A Lambda function consists of the code and associated dependencies, and it also has configuration information within it. You are the one who’s specifying the configuration information when creating a Lambda function. API is also provided so you can update some of the configuration data. Lambda function configuration information comes with critical elements like computing the resources needed, maximum execution time (timeout), IAM role (execution role), and handler name.

  • Calculating the required resources is done by specifying the amount of memory that you wish to allocate for your Lambda function. AWS Lambda allocates CPU power in proportion to the memory by the same ratio as a general-purpose Amazon EC2 instance type like an M3 type. In the example, it would mean that if you allocate 1024 MB of memory, your lambda function will get twice the CPU share than if you allocated 512 MB.
  • Maximum execution time (timeout) is specified to prevent the Lambda function from running non-stop. Since you’re paying for the AWS resources that are used to run your Lambda function, this comes quite handy. Upon reaching the timeout, AWS Lambda is terminating the execution of your Lambda function. The recommended setting is valued upon the expected execution time.
  • IAM role (execution role) is the role that AWS Lambda performs on your behalf when executing a lambda function.
  • Handler name is the method of entry point that runs your lambda function code with any event source dependencies included as a part of your lambda function. You will be able to discover more details, and the quality features of monitoring and debugging AWS Lambda and your Lambda functions by exploring our product features.

Triggering Lambda Function

AWS Lambda is operated by utilizing one of these two event models.

  • a push event model
  • a pull event model

Lambda functions can be written in Node.js (or JavaScript) and Java (Java 8 compatible). These are some of the events that can be configured to trigger the Lambda function.

  • Table updates in Amazon DynamoDB
  • Modifying objects in the S3 bucket
  • Messages that arrive at the Amazon Kinesis stream
  • Notifications that are sent from the Amazon SNS
  • HTTP events sent from API Gateway
  • Custom events coming from mobile applications, web applications, or any other web services

Lambda functions are small bits of more significant work done, allowing you to perform it seamlessly and effectively. Starting from scratch is always the best option especially for beginners in the field.

Hopefully, this article managed to find its way to the readers that are eager to learn and obtain some new knowledge about AWS Lambda and lambda functions. Feel free to post any questions in the comment sections below or even start a discussion about this topic.

Further reading:

How to deploy a Node.js application to AWS Lambda using Serverless Framework

AWS Lambda metrics you should definitely be monitoring

Top 6 AWS Lambda monitoring tools

Debugging with Dashbird: Lambda not logging to AWS CloudWatch

What are AWS Lambda triggers?

Free serverless monitoring

Read our blog

ANNOUNCEMENT: new pricing and the end of free tier

Today we are announcing a new, updated pricing model and the end of free tier for Dashbird.

4 Tips for AWS Lambda Performance Optimization

In this article, we’re covering 4 tips for AWS Lambda optimization for production. Covering error handling, memory provisioning, monitoring, performance, and more.

AWS Lambda Free Tier: Where Are The Limits?

In this article we’ll go through the ins and outs of AWS Lambda pricing model, how it works, what additional charges you might be looking at and what’s in the fine print.

More articles

Made by developers for developers

Dashbird was born out of our own need for an enhanced serverless debugging and monitoring tool, and we take pride in being developers.

What our customers say

Dashbird gives us a simple and easy to use tool to have peace of mind and know that all of our Serverless functions are running correctly. We are instantly aware now if there’s a problem. We love the fact that we have enough information in the Slack notification itself to take appropriate action immediately and know exactly where the issue occurred.

Thanks to Dashbird the time to discover the occurrence of an issue reduced from 2-4 hours to a matter of seconds or minutes. It also means that hundreds of dollars are saved every month.

Great onboarding: it takes just a couple of minutes to connect an AWS account to an organization in Dashbird. The UI is clean and gives a good overview of what is happening with the Lambdas and API Gateways in the account.

I mean, it is just extremely time-saving. It’s so efficient! I don’t think it’s an exaggeration or dramatic to say that Dashbird has been a lifesaver for us.

Dashbird provides an easier interface to monitor and debug problems with our Lambdas. Relevant logs are simple to find and view. Dashbird’s support has been good, and they take product suggestions with grace.

Great UI. Easy to navigate through CloudWatch logs. Simple setup.

Dashbird helped us refine the size of our Lambdas, resulting in significantly reduced costs. We have Dashbird alert us in seconds via email when any of our functions behaves abnormally. Their app immediately makes the cause and severity of errors obvious.