AWS Lambda—the Basics - Serverless Architectures with AWS Lambda

AWS Lambda—the Basics

Lambda is a high-scale, provision-free serverless compute offering based on functions. It provides the cloud logic layer for your application. Lambda functions can be triggered by a variety of events that occur on AWS or on supporting third-party services. They enable you to build reactive, event-driven systems. When there are multiple, simultaneous events to respond to, Lambda simply runs more copies of the function in parallel. Lambda functions scale precisely with the size of the workload, down to the individual request. Thus, the likelihood of having an idle server or container is extremely low. Architectures that use Lambda functions are designed to reduce wasted capacity.

Lambda can be described as a type of serverless Function-as-a-Service (FaaS). FaaS is one approach to building event-driven computing systems. It relies on functions as the unit of deployment and execution. Serverless FaaS is a type of FaaS where no virtual machines or containers are present in the programming model and where the vendor provides provision-free scalability and built-in reliability.

Figure 1 shows the relationship among event-driven computing, FaaS, and serverless FaaS.

The relationship among event-driven computing, FaaS, and
    serverless FaaS

Figure 1: The relationship among event-driven computing, FaaS, and serverless FaaS

With Lambda, you can run code for virtually any type of application or backend service. Lambda runs and scales your code with high availability.

Each Lambda function you create contains the code you want to execute, the configuration that defines how your code is executed and, optionally, one or more event sources that detect events and invoke your function as they occur. These elements are covered in more detail in the next section.

An example event source is API Gateway, which can invoke a Lambda function anytime an API method created with API Gateway receives an HTTPS request. Another example is Amazon SNS, which has the ability to invoke a Lambda function anytime a new message is posted to an SNS topic. Many event source options can trigger your Lambda function. For the full list, see this documentation. Lambda also provides a RESTful service API, which includes the ability to directly invoke a Lambda function. You can use this API to execute your code directly without configuring another event source.

You don’t need to write any code to integrate an event source with your Lambda function, manage any of the infrastructure that detects events and delivers them to your function, or manage scaling your Lambda function to match the number of events that are delivered. You can focus on your application logic and configure the event sources that cause your logic to run.

Your Lambda function runs within a (simplified) architecture that looks like the one shown in Figure 2.

Figure 2: Simplified architecture of a running Lambda function

Once you configure an event source for your function, your code is invoked when the event occurs. Your code can execute any business logic, reach out to external web services, integrate with other AWS services, or anything else your application requires. All of the same capabilities and software design principles that you’re used to for your language of choice will apply when using Lambda. Also, because of the inherent decoupling that is enforced in serverless applications through integrating Lambda functions and event sources, it’s a natural fit to build microservices using Lambda functions.

With a basic understanding of serverless principles and Lambda, you might be ready to start writing some code. The following resources will help you get started with Lambda immediately: