AWS Lambda

AWS Lambda is the serverless compute primitive on AWS. You ship a function — packaged as a zip, container image (up to 10 GB), or layer — and Lambda runs it on demand in response to events from 200+ AWS services and HTTP triggers, billing per millisecond of execution. SnapStart, ARM/Graviton runtimes, response streaming, function URLs, and Lambda@Edge extend the original event-driven model into low-latency APIs and globally-distributed compute.


Key Features:


Common Use Cases:


Service Limits & Quotas:


Pricing Model:


Code Example:


import json, os, boto3

dynamo = boto3.resource("dynamodb").Table(os.environ["TABLE_NAME"])

def lambda_handler(event, _ctx):
    """API Gateway proxy handler — store an event and return its id."""
    body = json.loads(event.get("body") or "{}")
    item = {
        "pk":      body["user_id"],
        "ts":      body["ts"],
        "payload": body.get("payload", {}),
    }
    dynamo.put_item(Item=item)
    return {
        "statusCode": 201,
        "headers":    {"content-type": "application/json"},
        "body":       json.dumps({"stored": True, "pk": item["pk"]}),
    }
  

Deploy and grant DynamoDB write access via AWS CLI:


zip -r function.zip handler.py

aws lambda create-function \
  --function-name store-event \
  --runtime python3.12 \
  --architectures arm64 \
  --memory-size 512 \
  --timeout 10 \
  --handler handler.lambda_handler \
  --role arn:aws:iam::123456789012:role/lambda-store-event \
  --zip-file fileb://function.zip \
  --environment 'Variables={TABLE_NAME=events}' \
  --snap-start ApplyOn=PublishedVersions
  


Common Interview Questions:

What causes Lambda cold starts and how do you mitigate them?

A cold start happens when Lambda spins up a new execution environment — pulling code, initializing the runtime, and running module-level init. Mitigations: provisioned concurrency, SnapStart (Java/Python/.NET), smaller deployment packages, ARM/Graviton, lazy imports, and avoiding heavy init.

How does Lambda concurrency work?

Each concurrent invocation needs its own execution environment. Account-wide concurrency starts at 1,000 (soft limit). Reserved concurrency caps a function's max concurrency (and reserves it). Provisioned concurrency keeps N pre-warmed environments at additional cost.

When would you choose Step Functions over chaining Lambdas directly?

Direct chaining works for simple flows but lacks built-in retries, error handling, observability, long-running waits, and parallelism. Step Functions adds explicit state, durable execution (up to a year), and visual debugging.

How does Lambda integrate with SQS, Kinesis, and DynamoDB Streams?

Via Event Source Mappings (ESM). Lambda polls the source on your behalf and invokes the function with batches. Tunables include batch size, batch window, parallelization factor (Kinesis/DynamoDB), and on-failure destinations.

How does memory affect Lambda performance and cost?

CPU and network bandwidth scale linearly with memory. A function may run faster (and cheaper overall) at 1024 MB than at 256 MB if it is CPU-bound. Use Lambda Power Tuning to find the right setting empirically.

What is SnapStart and what are its limitations?

SnapStart takes a Firecracker microVM snapshot after init and restores it on invocation, eliminating most cold-start cost. Available for Java, Python, and .NET. Limitations: requires versioned functions, networking state must be re-initialized post-restore, not compatible with provisioned concurrency on the same alias.

How do you keep VPC-attached Lambdas fast?

Lambda uses Hyperplane ENIs that are shared across invocations, so VPC cold-start penalty is small. Use VPC endpoints for AWS service calls and put functions in private subnets with NAT only when necessary.


AWS Lambda is the default serverless compute on AWS — pay-per-millisecond, scales to zero, and integrates with virtually every AWS service. With SnapStart, ARM, and response streaming, modern Lambda is competitive even with low-latency and large-payload workloads that previously needed always-on services.