Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSCompute

AWS Lambda

Serverless compute service — run code without provisioning servers, covering concurrency, cold starts, layers, destinations, and event-driven patterns.

Overview

AWS Lambda is a serverless compute service — run code in response to events without provisioning or managing servers. Lambda automatically scales from zero to thousands of concurrent executions and charges only for actual compute time consumed.

Lambda supports multiple runtimes (Python, Node.js, Java, .NET, Go, Ruby, custom via container images or custom runtimes) and integrates natively with over 200 AWS services as event sources or targets.


Core Concepts

ConceptDescription
FunctionThe unit of deployment — code + configuration (runtime, memory, timeout, IAM role)
Event SourceThe AWS service or custom application that triggers a function invocation
InvocationA single execution of a function; can be synchronous, asynchronous, or poll-based
Execution EnvironmentA secure, isolated micro-VM (Firecracker) that runs the function code
HandlerThe entry-point method that Lambda calls when the function is invoked
LayerA ZIP archive containing libraries, custom runtimes, or configuration shared across functions
ConcurrencyThe number of in-flight invocations at any given time
Cold StartLatency penalty when Lambda creates a new execution environment (init + code download + runtime boot)
DestinationsRouting targets for async invocation results — success and failure sent to SQS, SNS, Lambda, or EventBridge

Invocation Models

ModelTrigger ExamplesRetry BehaviourError Handling
SynchronousAPI Gateway, ALB, SDK InvokeCaller retries; Lambda returns error immediatelyError returned to caller
AsynchronousS3, SNS, EventBridge, CloudWatch EventsLambda retries twice (configurable); then sends to DLQDead-Letter Queue (DLQ) or Destinations
Poll-basedSQS, Kinesis, DynamoDB Streams, KafkaLambda polls and retries until record expires or succeedsBisect batch on error; DLQ on source (SQS)

Exam Trap: For asynchronous invocations, Lambda handles retries automatically (up to 2 additional attempts). The caller does not receive error responses — configure a Dead-Letter Queue or Destination to capture failures.


Concurrency

Concurrency TypeDescription
UnreservedDefault pool shared across all functions in the account (default limit: 1,000 per region)
ReservedGuarantees a set number of concurrent executions for a specific function
ProvisionedPre-initialises execution environments to eliminate cold starts; charged when idle
Account concurrency limit (e.g., 1,000)
├── Function A: Reserved = 100  (guaranteed, capped at 100)
├── Function B: Reserved = 200  (guaranteed, capped at 200)
└── Unreserved pool = 700       (shared by all other functions)

SAA/SAP Tip: Reserved Concurrency both guarantees and caps a function's concurrency. Setting it to 0 effectively throttles the function. Provisioned Concurrency eliminates cold starts but incurs cost even when idle.


Cold Starts

Cold starts occur when Lambda creates a new execution environment. The latency depends on:

FactorImpact
RuntimeInterpreted languages (Python, Node.js) start faster than compiled (Java, .NET)
Package sizeLarger deployment packages increase download and extraction time
VPC attachmentFunctions in a VPC previously had extra ENI setup time; Hyperplane now reduces this significantly
Memory allocationHigher memory = proportionally more CPU = faster init

Mitigation Strategies

  • Provisioned Concurrency — pre-warm execution environments; eliminates cold starts entirely
  • SnapStart (Java) — snapshots the initialised JVM state; restores from cache on invocation
  • Keep functions warm — schedule periodic pings (workaround, not recommended at scale)
  • Minimise package size — exclude unused dependencies; use layers for shared libraries

Lambda Layers

Layers separate dependencies from function code, enabling reuse across functions.

  • Up to 5 layers per function
  • Total unzipped deployment size (function + layers) ≤ 250 MB
  • Layers are versioned and immutable once published
  • Common use: shared SDKs, database drivers, custom runtimes

Lambda@Edge and CloudFront Functions

FeatureLambda@EdgeCloudFront Functions
RuntimeNode.js, PythonJavaScript only
Execution locationRegional edge caches400+ CloudFront edge locations (PoPs)
Max execution time5 s (viewer) / 30 s (origin)< 1 ms
Max memory128–10,240 MB2 MB
Use caseA/B testing, auth, origin selection, image transformHeader manipulation, URL rewrites, cache key normalisation

Event Source Mapping

Event Source Mappings (ESMs) allow Lambda to poll stream and queue sources automatically.

SourceBatchingParallelisationError Handling
SQS1–10,000Up to 1,000 concurrent batchesMessage returns to queue on failure
Kinesis / DynamoDB Streams1–10,000Up to 10 per shardBisect batch, retry, or skip
Kafka (MSK / self-managed)1–10,000Per-partitionRetry until success or record expires

Limits (Key Defaults)

ResourceDefault Limit
Memory128 MB – 10,240 MB
TimeoutUp to 15 minutes
Deployment package (zipped)50 MB (direct) / 250 MB (S3)
Ephemeral storage (/tmp)512 MB – 10,240 MB
Concurrent executions1,000 per region (soft)
Environment variables4 KB total
Layers per function5

Common Use Cases

  • API backend — Pair with API Gateway or ALB for fully serverless HTTP endpoints with per-request billing.
  • Event-driven data processing — Trigger from S3 uploads, DynamoDB Streams, or Kinesis for real-time ETL and enrichment.
  • Scheduled tasks — Use EventBridge rules to run cron-like jobs without maintaining a server.
  • Stream processing — Poll Kinesis or Kafka topics via ESM for real-time analytics pipelines.
  • ChatOps and automation — Respond to SNS notifications, CloudWatch alarms, or CodePipeline events with automated remediation.
  • Edge computing — Lambda@Edge for request/response manipulation at CloudFront edge locations.

SAA/SAP Exam Tips

SAA/SAP Tip: Lambda has a 15-minute maximum timeout. For workloads exceeding this, consider Step Functions (orchestrate multiple Lambdas), AWS Batch, or ECS/Fargate tasks.

Exam Trap: Lambda functions in a VPC require subnets with available IP addresses and a NAT Gateway (or VPC endpoint) to reach the internet or AWS services outside the VPC. A function with no route to the internet will fail to call external APIs.

SAA/SAP Tip: For "serverless" + "lowest operational overhead" questions, Lambda is typically the answer. For "serverless containers," the answer is Fargate — not Lambda.

Exam Trap: Reserved Concurrency set to 0 acts as a kill switch — the function cannot be invoked at all. This is sometimes used intentionally to disable a function in an emergency.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAWS LambdaBaseline
AzureAzure FunctionsSimilar event-driven model; Durable Functions built-in
GCPGoogle Cloud Functions / Cloud RunCloud Run also supports containers natively
On-PremisesOpenFaaS, Knative, Apache OpenWhiskSelf-hosted FaaS frameworks on Kubernetes

Pricing Model

DimensionUnitNotes
RequestsPer 1 millionFirst 1M requests/month free
DurationPer ms (GB-seconds)Proportional to allocated memory; first 400K GB-s/month free
Provisioned ConcurrencyPer GB-s allocatedCharged whether invoked or not
Ephemeral storagePer GB-s above 512 MB512 MB included free
Data transfer outPer GBStandard EC2 data transfer rates apply

Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page