DEV Community

Cover image for Day 20 - AWS Lambda
Rahul Joshi
Rahul Joshi

Posted on

Day 20 - AWS Lambda

Cloud computing has evolved dramatically over the last decade.

The journey looked something like this:

Physical Servers
        ↓
Virtual Machines
        ↓
Containers
        ↓
Serverless Computing
Enter fullscreen mode Exit fullscreen mode

One of the biggest innovations in cloud computing is AWS Lambda.

Instead of managing:

  • Servers
  • Operating Systems
  • Patching
  • Scaling
  • Capacity Planning

You simply upload code and AWS runs it.

This is the foundation of Serverless Computing.


What is AWS Lambda?

AWS Lambda is a serverless compute service that allows you to run code without provisioning or managing servers.

You upload a function and AWS executes it whenever an event occurs.

Example:

User Uploads Image
        ↓
S3 Event Triggered
        ↓
Lambda Function Runs
        ↓
Image Processed
Enter fullscreen mode Exit fullscreen mode

You only pay for execution time.

No execution means:

No Cost
Enter fullscreen mode Exit fullscreen mode

Why AWS Introduced Lambda

Before Lambda, deploying applications looked like this:

Provision EC2
       ↓
Install Runtime
       ↓
Deploy Application
       ↓
Monitor Servers
       ↓
Scale Infrastructure
       ↓
Patch OS
Enter fullscreen mode Exit fullscreen mode

Even small applications required infrastructure management.

AWS wanted developers to focus on:

Business Logic
Enter fullscreen mode Exit fullscreen mode

Instead of:

Infrastructure Management
Enter fullscreen mode Exit fullscreen mode

Thus Lambda was introduced in 2014.


What is Serverless?

Serverless does NOT mean servers don't exist.

Servers still exist.

AWS manages them for you.

Instead of:

You Manage Servers
Enter fullscreen mode Exit fullscreen mode

Lambda provides:

AWS Manages Servers
You Manage Code
Enter fullscreen mode Exit fullscreen mode

Lambda works

Example:

API Gateway
       ↓
Lambda
       ↓
DynamoDB
Enter fullscreen mode Exit fullscreen mode

Benefits of AWS Lambda


1. No Server Management

No:

  • EC2
  • OS updates
  • Capacity planning

2. Automatic Scaling

AWS automatically scales functions.

1 Request
      ↓
1 Lambda Instance

1000 Requests
      ↓
1000 Lambda Instances
Enter fullscreen mode Exit fullscreen mode

3. Pay Per Use

You only pay for:

Requests
+
Execution Duration
Enter fullscreen mode Exit fullscreen mode

4. Event Driven

Lambda reacts to events.

Examples:

  • API requests
  • S3 uploads
  • SNS notifications
  • SQS messages
  • DynamoDB streams

5. High Availability

AWS automatically distributes Lambda execution across Availability Zones.


Supported Programming Languages

AWS Lambda supports multiple runtimes.


Python

Popular for:

  • Automation
  • AI/ML
  • Data processing

Example:

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
Enter fullscreen mode Exit fullscreen mode

Node.js

Popular for:

  • APIs
  • Web applications

Java

Popular for:

  • Enterprise workloads

.NET

Popular for:

  • Microsoft environments

Go

Popular for:

  • High performance
  • Fast startup

Custom Runtime

Using Custom Runtime API, you can run:

  • Rust
  • PHP
  • Other languages

Lambda Function Components

Every Lambda contains:


Function Code

Your business logic.


Runtime

Language execution environment.

Example:

Python 3.12
Node.js 20
Java 21
Enter fullscreen mode Exit fullscreen mode

Handler

Entry point of Lambda.

Example:

lambda_handler(event, context)
Enter fullscreen mode Exit fullscreen mode

AWS invokes this function.


Event

Input to the Lambda.

Example:

{
  "bucket": "images"
}
Enter fullscreen mode Exit fullscreen mode

Context

Runtime information.

Contains:

  • Request ID
  • Timeout
  • Memory

Lambda Execution Lifecycle

Request Arrives
        ↓
Environment Created
        ↓
Function Runs
        ↓
Response Returned
Enter fullscreen mode Exit fullscreen mode

Understanding Cold Starts

One of the most important Lambda concepts.


Cold Start

When Lambda has no running execution environment:

Request Arrives
       ↓
Create Environment
       ↓
Load Runtime
       ↓
Execute Function
Enter fullscreen mode Exit fullscreen mode

Extra startup time occurs.


Warm Start

If environment already exists:

Request Arrives
       ↓
Execute Function Immediately
Enter fullscreen mode Exit fullscreen mode

Faster response.


What is Concurrency?

Concurrency means:

How Many Functions
Can Run Simultaneously
Enter fullscreen mode Exit fullscreen mode

Example:

100 Requests
       ↓
100 Concurrent Executions
Enter fullscreen mode Exit fullscreen mode

Reserved Concurrency

Reserve capacity for critical workloads.

Example:

Payment Function
Reserved = 100
Enter fullscreen mode Exit fullscreen mode

Always guaranteed.


Provisioned Concurrency

Used to eliminate cold starts.

AWS keeps execution environments warm.

Useful for:

  • APIs
  • User-facing workloads

What is Lambda Scaling?

Lambda automatically scales horizontally.

1 Request
       ↓
1 Environment

10000 Requests
       ↓
10000 Environments
Enter fullscreen mode Exit fullscreen mode

No manual scaling required.


What is a Lambda Layer?

One of the most important Lambda concepts.

Lambda Layers allow sharing code across multiple functions.

Without Layers:

Function A
 └─ boto3

Function B
 └─ boto3

Function C
 └─ boto3
Enter fullscreen mode Exit fullscreen mode

Duplication occurs.


With Layers

Layer
 └─ boto3

Function A
Function B
Function C
Enter fullscreen mode Exit fullscreen mode

All functions share the same dependency.


Why Lambda Layers Matter

Benefits:

  • Smaller deployment packages
  • Reusability
  • Easier maintenance
  • Faster deployments

Common Layer Use Cases

Python Libraries

numpy
pandas
requests
Enter fullscreen mode Exit fullscreen mode

Monitoring Agents

Datadog
New Relic
OpenTelemetry
Enter fullscreen mode Exit fullscreen mode

Lambda Storage Options


Temporary Storage

/tmp
Enter fullscreen mode Exit fullscreen mode

Default:

512 MB
Enter fullscreen mode Exit fullscreen mode

Can be increased.


Amazon S3

Persistent object storage.

Used for:

  • Files
  • Images
  • Backups

Amazon EFS

Network file system for Lambda.

Useful for:

  • Shared storage
  • Large datasets

Event Sources for Lambda


API Gateway

User Request
      ↓
API Gateway
      ↓
Lambda
Enter fullscreen mode Exit fullscreen mode

Most common pattern.


Amazon S3

File Uploaded
      ↓
Lambda Triggered
Enter fullscreen mode Exit fullscreen mode

Lambda and VPC

By default:

Lambda
     ↓
AWS Managed Network
Enter fullscreen mode Exit fullscreen mode

For private resources:

Lambda
     ↓
VPC
     ↓
RDS
Enter fullscreen mode Exit fullscreen mode

Lambda can connect to:

  • RDS
  • ElastiCache
  • Private APIs

Lambda with RDS

Common architecture:

API Gateway
      ↓
Lambda
      ↓
Aurora MySQL
Enter fullscreen mode Exit fullscreen mode

Challenges:

  • Connection management
  • Database scaling

Solution:

RDS Proxy
Enter fullscreen mode Exit fullscreen mode

Lambda Monitoring


CloudWatch Logs

Automatically captures:

  • stdout
  • stderr
  • application logs

CloudWatch Metrics

Monitor:

  • Invocations
  • Duration
  • Errors
  • Throttles
  • Concurrent executions

AWS X-Ray

Distributed tracing for Lambda applications.

Useful for:

  • Performance analysis
  • Bottleneck detection

Lambda Security


IAM Roles

Lambda should never use hardcoded credentials.

Use:

IAM Execution Role
Enter fullscreen mode Exit fullscreen mode

Secrets Manager

Store:

  • Database passwords
  • API keys
  • Tokens

KMS Encryption

Encrypt:

  • Environment variables
  • Data

Lambda Limits

Some important limits:

Feature Limit
Timeout 15 Minutes
Memory 128 MB – 10 GB
Ephemeral Storage Up to 10 GB
Deployment Package 50 MB ZIP
Container Image 10 GB

ec2


Lambda Container


Real-World Lambda Use Cases


Image Processing

S3 Upload
      ↓
Lambda
      ↓
Resize Image
Enter fullscreen mode Exit fullscreen mode

Serverless APIs

API Gateway
      ↓
Lambda
      ↓
DynamoDB
Enter fullscreen mode Exit fullscreen mode

Log Processing

CloudWatch Logs
       ↓
Lambda
       ↓
Elasticsearch/OpenSearch
Enter fullscreen mode Exit fullscreen mode

Scheduled Jobs

EventBridge
      ↓
Lambda
      ↓
Daily Report
Enter fullscreen mode Exit fullscreen mode

Production Best Practices

Keep Functions Small

One function = one responsibility.


Use Layers

Avoid dependency duplication.


Enable Monitoring

Use:

  • CloudWatch
  • X-Ray

Use Provisioned Concurrency

For latency-sensitive APIs.


Use RDS Proxy

For database-heavy workloads.


Secure Secrets

Use:

  • Secrets Manager
  • Parameter Store

Never hardcode credentials.



Final Thoughts

AWS Lambda transformed cloud computing by allowing developers to focus entirely on code.

Instead of managing:

Servers
Operating Systems
Scaling
Patching
Enter fullscreen mode Exit fullscreen mode

you simply write functions and AWS handles the infrastructure.

Lambda is ideal for:

  • APIs
  • Event-driven applications
  • Automation
  • Data processing
  • Serverless architectures

Understanding concepts like:

  • Layers
  • Cold Starts
  • Concurrency
  • Provisioned Concurrency
  • Event Sources
  • RDS Proxy

is essential for designing production-grade serverless applications.

For modern cloud engineers, AWS Lambda is no longer optional—it is one of the most important services in the AWS ecosystem.

Top comments (0)