Home/Blog/Programming/What is AWS Lambda? Serverless computing for software developers
Home/Blog/Programming/What is AWS Lambda? Serverless computing for software developers

What is AWS Lambda? Serverless computing for software developers

Cameron Wilson
Jan 11, 2024
10 min read

Become a Software Engineer in Months, Not Years

From your first line of code, to your first day on the job — Educative has you covered. Join 2M+ developers learning in-demand programming skills.

Serverless and cloud computing have seen a major uptake in recent years, becoming industries unto themselves, with AWS Lambda leading the way.

Companies are making the switch to serverless architecture for shorter time to market and decreased operational costs, but for developers the advantage lies in the ability to offload the burden of managing infrastructure to serverless platforms, so you can focus on building even better apps.

In this article, we will look at:


Deploy your own applications on the cloud

Master new Severless tools with hands-on AWS Lambda lessons.

Running Serverless Applications with AWS Lambda


What is AWS Lambda#

widget

AWS Lambda is a serverless computing service, or FaaS (Function as a Service) provided by Amazon Web Services. It supports a wide array of potential triggers, including incoming HTTP requests, messages from a queue, customer emails, changes to database records, user authentication, messages coming to web sockets, client device synchronization, and much more. AWS Lambda also helps you to focus on your core product and business logic instead of managing the operating system (OS) access control, etc.

Because application developers do not package or distribute the server code to control a network socket in AWS Lambda, their applications are serverless. The buzzword ‘serverless’ is a bit misleading, as there are still servers in a serverless environment.


Languages supported by AWS Lambda#

AWS Lambda supports:

AWS also provides a Runtime API which allows you to use any additional programming languages to use your functions.

It’s also suggested that you check deprecated runtimes to ensure you’re using the most updated runtime. Acceptable runtimes for a few of the above languages are: Java 11, Python 3.8, and Node.js 12.x. Some deprecated runtimes include: Node.js 8.10 and Python 2.7.


What are serverless applications#

Serverless applications, at the most basic technical level, are software that runs in an environment where the hosting provider is fully responsible for infrastructural and operational tasks. These include receiving network requests, scaling the computing infrastructure on demand, monitoring, and recovery.

Instead of containers bundling application business logic with an operating system, they bundle network servers (such as web servers or message brokers) and business logic code. S

erverless applications only need to provide the code that should run when an event happens and configure the triggers in the execution environment to call that code.

In the Amazon Web Services cloud, the execution environment for serverless code is called AWS Lambda.


Events that trigger AWS Lambda#

  • HTTP requests via Amazon API Gateway
  • Modifications to objects in Amazon S3 buckets
  • Updates to a DynamoDB Table
  • State transitions in AWS Step Functions

How does AWS Lambda work?#

Clients send data to Lambda. Clients could be anyone who’s sending requests to AWS Lambda. This could be an application or other Amazon services.

Lambda receives requests and depending on the size, amount, or volume of the data, it runs on the defined number of containers. Requests are then given to a container to handle. A container contains the code the user has provided to satisfy the query.

With an increased number of requests, an increasing number of containers are created. If the number of requests reduces, the number of containers are reduced as well.

widget

AWS Lambda concepts#


Function#

A function is a resource that runs your code in AWS Lambda. Functions contain code that process events, and a runtime that passes requests and responses between Lambda and the function. You provide the code, and you can use the provided runtimes or create your own.


Runtime#

Lambda runtimes allow functions in different languages to run in the same base execution environment. You configure your function to use a runtime that matches your programming language.


Event#

An event is a JSON formatted document that contains data for a function to process. The Lambda runtime converts the event to an object and passes it to your function code. When you invoke a function, you determine the structure and contents of the event. When an AWS service invokes your function, the service defines the event.


Concurrency#

Concurrency is the number of requests that your function is serving at any given time. When your function is invoked, Lambda provisions an instance of it to process the event. When the function code finishes running, it can handle another request. If the function is invoked again while a request is still being processed, another instance is provisioned, increasing the function’s concurrency.


Trigger#

A trigger is a resource or configuration that invokes a Lambda function. This includes AWS services that can be configured to invoke a function, applications that you develop, and event source mappings.


Lambda layers#

Lambda layers are an important distribution mechanism for libraries, custom runtimes, and other important function dependencies. This AWS component also helps you to manage your development function code separately from the unchanging code and resources that it uses.


Keep the learning going.#

Learn AWS Lambda without scrubbing through videos or documentation. Educative’s text-based courses are easy to skim and feature live coding environments - making learning quick and efficient.

Running Serverless Applications with AWS Lambda


When to use AWS Lambda#


Maximizing throughput#

Lambda is great for use cases where throughput is critical and the tasks parallelize nicely.

Typical web requests for dynamic content, involving access to a back-end database, or some user data manipulation usually fall into this category. Automatic email replies or chatbots are also a nice example.

Any single request taking a few hundred milliseconds more than average won’t be noticeable to typical users and Lambda will ensure that everyone gets served relatively quickly regardless of traffic spikes.


Splittable, longer-running tasks#

Longer on-demand computational tasks that can execute in less than 15 minutes, or could be split into independent segments that take less than 15 minutes, are also a good use case for Lambda.

In these cases, the few hundred milliseconds required for Lambda functions to start won’t make an important difference to processing time. Some nice examples of tasks that fall into this category are file format conversions, generating previews or thumbnails, and running periodic reports.


High availability tasks#

Tasks that need high availability and good operational infrastructure, but do not need to guarantee latency, are also a great use case for AWS Lambda. This includes payment notifications from external systems, for example, PayPal or Stripe.

These notifications must be handled reliably and relatively quickly, they might have unpredictable traffic patterns, and yet it’s not critically important if they are finished in one second or two seconds.


When to avoid AWS Lambda#

There are four important technical limitations that you need to consider when evaluating whether something should run in Lambda:

  • No session affinity
  • Non-deterministic latency
  • Execution time-limited to 15 minutes
  • No direct control over processing power

Latency guaranteed tasks#

Lambda is currently not suitable for tasks that require guaranteed latency, such as in high-frequency trading systems or near-real-time control systems.

If a task must be handled in under 10 or 20 ms, it’s much better to create a reserved cluster and have services directly connected to a message broker.


Longer-running tasks#

Another category where Lambda isn’t suitable right now is tasks that could potentially run for longer than 15 minutes. One notable example is video transcoding for large files.

Connecting to a socket and consuming a continuous data feed is also not a good use case for Lambda, due to the time limit.


Tasks that demand high-processing power#

The third category where you should not use Lambda right now is tasks that require a huge amount of processing power and coordination.

For example, video rendering. Tasks like that are better suited to a reserved infrastructure with a lot of CPUs (or even GPUs).


Tasks that require no on-demand computation#

Lastly, tasks that require no on-demand computation, such as serving static web files, are a poor use case for Lambda. In theory, it’s possible to use Lambda as a web server and send images and CSS files to clients, but this is a waste of money.

It is much cheaper and faster to use a specialized product for that, for example, a content delivery network.

svg viewer

Essential parts of AWS#


EC2#

Amazon EC2 (Elastic Compute Cloud) is an IaaS (Infrastructure as a Service) that provides virtualized computing resources. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster.


S3#

Amazon S3 (Simple Storage Service) is the cloud storage service of AWS. It allows you to store and retrieve any amount of data, at any time, from anywhere on the web.


CloudFront#

CloudFront is a content delivery network service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users.


Amazon API Gateway#

Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale.


SAM (Serverless Application Model)#

An open-source framework for building serverless applications. It is a set of products that simplify developing, testing, and deploying applications using AWS Lambda.

One part of SAM runs on developer machines and build servers, helping to prepare for deployment. Another aspect of SAM runs in AWS data centers during the deployment process.

AWS offers over 170 services, but it’s hard to know which are the best to use.

Here’s our Quick AWS Tutorial of top services, chosen by real developers.


How to get started with AWS Lambda#

  • Step 1

    Head on over to their sign in page. If you don’t have an AWS account, go ahead and create one. Then find “Lambda” under “Compute” and click to open the AWS Lambda Console.

  • Step 2

    Select a Lambda blueprint. In the AWS Lambda console, select “Create a Function”.

  • Step 3

    Configure and create your lambda function. Here is where you enter the basic information about your Lambda function (i.e. things like name, role, and role name). Then click “create function”.

  • Step 4

    Invoke Lambda function and verify results. Click “configure test event” in the upper right hand drop down menu.


Best practices for AWS Lambda#

  • When to VPC-Enable a Lambda Function

    You should only enable your functions for VPC access when you need to interact with a private resource located in a private subnet. An RDS instance is a good example.

  • Deploy Common Code to a Lambda Layer (i.e. the AWS SDK)

    If you intend to reuse code in more than one function, consider creating a Layer and deploying it there. A great candidate would be a logging package that your team is required to standardize on.

  • Watch Your Package Size and Dependencies

    Remove all unnecessary items, such as documentation and unused libraries.


What to learn next#

This was your first step toward an exciting cloud computing career. Some next topics to look at are:

  • HTTP request implementations
  • External storage management
  • Utilizing Lambda Layers
  • Workflow and session management

To help you along that journey, Educative has created the course Running Serverless Applications with AWS Lambda.

This course by award winning serverless computing author Gojko Adzic gives you hands on hands-on experience with advanced AWS topics. By the end of the course, you’ll be an expert in managing user workflows, handling HTTP events, and designing your own robust applications.

Happy learning!


Continue learning about cloud computing#

Frequently Asked Questions

What language does AWS Lambda use?

AWS Lambda supports multiple programming languages, including Python, Node.js (JavaScript), Ruby, Java, Go, .NET Core (C#), and PowerShell.


  

Free Resources