AWS Lambda is a serverless compute service that lets you run your code without managing any servers. Developers can use Lambda functions to create various applications that respond to events or run processes on a schedule.

Everything sounds simple, but where and how can you get started using it?

This article will cover the most important information about AWS Lambda, including AWS Lambda common use cases, code examples of Lambda integrations with various AWS services, and potential anti-patterns for using it. Let’s get started!

What Is AWS Lambda?

Serverless computing is a significant paradigm shift from traditional virtualization, allowing you to eliminate operational efforts on managing compute resources and focus on the applications development process.

AWS Lambda is an AWS compute service that enables you to run code without provisioning or managing servers. You can use AWS Lambda to run code responding to events, such as changes to data in Amazon S3 buckets, messages arriving in Amazon Kinesis data streams, or executing periodic tasks.

With AWS Lambda, you don’t have any servers to manage because the function code execution runtime is managed by AWS, including patching and managing the underlying hardware, networking, and security. When the code of the Lambda function is not executed, your function code is not running.

To create an AWS Lambda function, you need to deploy its code to the AWS Lambda service using the AWS Lambda console or Lambda API:

Every Lambda function execution time is limited to 15 mins, so if you need to build a complex workflow, consider splitting your code into multiple Lambda functions and using Step Functions to orchestrate their execution.

AWS Lambda scales automatically to handle traffic spikes or workload increases. When needed, AWS automatically provides additional compute capacity (runs Lambda functions).

Pricing

AWS Lambda pricing is straightforward. You pay per AWS Lambda invocation request and its execution time. The free tier includes 1,000,000 requests and 400,000 GB-seconds of compute time (each Lambda function can have from 128 MB to 10,240 MB of RAM).

Benefits Of AWS Lambda

AWS Lambda supports many programming languages, including Python, Java, C#, Node.js, .NET, Ruby, Go, and custom runtimes. It is also integrated with all AWS services.

Monitoring Lambda functions can be simplified by using AWS CloudWatch, X-Ray, or third-party serverless monitoring solutions. Increasing Lambda function memory (RAM) can improve CPU and network performance.

When you increase Lambda function memory (RAM), AWS will automatically improve Lambda function CPU and network performance.

AWS Lambda also supports Lambda Container Images. The container image must implement Lambda Runtime API.

AWS Lambda Limits

First, you must know that AWS Lambda is a regional AWS service (AWS Global Infrastructure: Regions and Availability Zones).

Next, there are some critical Lambda execution limits:

  • Memory allocation: 128 MB – 10 GB (1 MB increments)
  • Maximum execution time: 900 seconds (15 minutes)
  • Environment variables: 4 KB limit – all environment variables and their data can’t be more than 4 KB
  • Temporary disk storage (/tmp folder): 512 MB – 10 GB
  • Concurrent executions (provisioned concurrency): by default, up to 1,000 (can be increased)

Lambda deployment limits

  • Lambda function deployment size (compressed ZIP archive): 50 MB
  • Uncompressed size of Lambda function: 250 MB (for a larger Lambda functions codebase, use /tmp folder or EFS volumes)

Lambda Integrations

AWS Lambda is integrated with all AWS services and AWS resources, here are some of the most widely used integrations:

A Quick Intro To AWS Lambda – Getting Started Guide - Lambda integrations

Amazon API Gateway

You can integrate AWS Lambda with API Gateway to build serverless web and mobile backends for your applications.

Amazon Kinesis

Kinesis Data Firehose is using AWS Lambda to do data transformations on the fly.

Amazon DynamoDB

DynamoDB streams (DB data changes) can be sent to AWS Lambda to give you the ability to react to them.

Amazon S3

One of the common patterns to process files uploaded to an S3 bucket is using AWS Lambda functions.

Amazon CloudFront

Amazon CloudFront is integrated with Lambda@Edge to help with HTTP requests’ transformations and filtering on the fly.

EventBridge

EventBridge is integrated with AWS Lambda and allows Lambda to react to various events in AWS infrastructure. We can automatically react to this event whenever something happens within AWS.

Amazon CloudWatch

AWS Lambda is integrated with CloudWatch, allowing you to react to any string pattern in your application logs, send custom business metrics to CloudWatch and build custom Dashboards based on that data.

SNS

Lambda can subscribe to an SNS topic and automatically react to SNS notifications.

SQS

Lambda functions can process messages coming from SQS queues.

Cognito

You can customize your web application users’ authentication flow using Lambda integration with Cognito.

Other services

For more information on the integration of AWS Lambda with other AWS services, check the AWS Lambda Use Cases – The Ultimate List article.

Examples Of Using AWS Lambda

You may find many code examples you can use in AWS Lambda to interact with various AWS services in our Python Boto3 Tutorials. Here, we’d like to mention a couple of the most common examples of using Lambda:

Using AWS Lambda for thumbnails and GIFs generation

Building Thumbnails And GIFs Generator Using Lambda And FFmpeg

Example of using AWS Lambda as a AWS CRON job (Scheduled Lambda Functions)

Cloud CRON - Scheduled Lambda Functions - Example

AWS Step Functions – How to manage long-running tasks

Using Step Functions for workflow orchestration

Anti-Patterns

AWS Lambda provides broad functionality for you to build applications as needed. While this flexibility is essential, it can also lead to technically functional designs that may be suboptimal from an architecture and cost point of view. Here are examples of how you may not want to use Lambda functions.

Additionally, it is crucial to:

Some time ago, I published a list of Issues to Avoid When Implementing Serverless Architecture with AWS Lambda in the AWS Architecture blog, which covers additional aspects of improving and optimizing your Lambda functions use cases.

Summary

In this article, we’ve summarized all the required information to start with AWS Lambda. Please let us know in the comments section below if you have any comments or suggestions.