AWS - Introduction to Serverless Architecture - Lambda

Subscribe Send me a message home page tags


Table of Contents

Introduction

Serveless applications are ones that don't require you to provision or manage any servers. They provide the following benefits:

A typical AWS serverless architecture might have the following components:

As we can see in the above list, the computing component in a typical serverless architecture is AWS Lambda Service. It follows the Function-as-a-Service (FaaS) approach where the unit of execution and execution is functions. Lambda provides the ultimate abstraction because everything except the business logic is handled by AWS automatically. Lambda functions scale automatically and precisely with the size of the workload which makes it very handy when we build event-driven computing systems. For each event, a separate Lambda instance is triggered, therefore the execution is completely independent.

In this pose, we will cover the following aspect of Lambda function:

Lambda Function Code

Ultimately, a Lambda function is just a piece of code. To execute codes, we need to provide

To execute a function, we need to provide

For AWS Lambda function, the execution runtime environment is based on an Amazon Linux AMI. The code and dependencies are stored in the Function Code Package. In AWS terms, the code and dependencies are assets. As Lambda is used in event-driven system, the inputs to a Lambda function are information about the event that triggered the function and the context such as AWS request ID, remaining time and logging hook. The inputs are provided in an Event object and the context is provided to Lambda function through a Context object.

What happens when an event occurs and triggers a Lambda function?

As events occur, the code package will be downloaded from the S3 bucket, installed in the Lambda runtime environment, and invoked as needed. Once the environment (more precisely, the function container) is set up, it remains active for a while and can be used by subsequent Lambda invocation. If a Lambda invocation runs on a re-used function container, we say it's running on a warm container; otherwise, we say the invocation is experiencing a cold start. Here is the diagram copied from AWS website

warm_container_and_cold_start.jpg

Lambda Configuration

We can configure the following properties of a Lambda function:

Lambda Event Source

Lambda functions can be triggered by events from the following services:

There are three invocation types:

Here the synchronous and asynchronous execution is related to the request-response process. For a synchronous execution, we will wait for the completion of the execution before sending a response to the requester. On the contrary, for an asynchronous execution, we could reply to the requester immediately without waiting.

Services that invoke Lambda functions synchronously

Services that invoke Lambda functions asynchronously

There are two invocation models:

Quick Notes

How to create a Lambda function?

we can create a Lambda function through the AWS console or use CreateFunction API.

How to test Lambda function locally?

We can use AWS SAM Local for local testing

How to manage access?

Lambda function may need to access other AWS resources. The access should be granted through IAM role. In this way, we don't need to save the access key information for the execution.

----- END -----

Welcome to join reddit self-learning community.
Send me a message Subscribe to blog updates

Want some fun stuff?

/static/shopping_demo.png