█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/DevOps and Infrastructure/Cloud Platforms — AWS/Lambda
45 minIntermediate

Lambda

After this lesson, you will be able to: Build a Lambda function: triggers, execution model, cold starts, and connecting to other AWS services with the SDK.

Lambda is the original serverless. Pay per invocation, no servers to manage. This lesson covers the model + the gotchas.

Prerequisites:RDS

The Lambda model

Write a function in Node / Python / Java / Go / Ruby / .NET / custom runtime. AWS runs it on demand: in response to an event (HTTP, SQS message, S3 upload, schedule). You pay for: invocation count + (memory * duration). Free tier: 1M invocations + 400K GB-seconds per month. Limits: 15 min max duration; 10 GB memory; 50 MB zip / 250 MB layer; 6 MB sync payload / 256 KB async.

A Lambda handler (Node.js)

The handler is the entry point AWS calls on each invocation.

tsx
// index.mjs
export const handler = async (event, context) => {
console.log("Event:", JSON.stringify(event));
// For an API Gateway HTTP trigger:
const name = event.queryStringParameters?.name ?? "world";
return {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: `Hello, ${name}` }),
};
};
// Deploy via:
// - Console upload (zip the file)
// - AWS SAM (sam deploy)
// - Serverless Framework
// - Terraform / Pulumi / CDK
// - Just docker push to ECR + select 'container image' as the deploy method

Triggers: what fires the function

API Gateway: synchronous HTTP. Build REST or HTTP APIs. Function URL: simpler than API Gateway; one URL per function. Free; built-in. S3: object created/deleted. Async. SQS / SNS / EventBridge: queues + events. Async. CloudWatch Events / Scheduler: cron. DynamoDB Streams: react to DB changes. Direct invoke from SDK: call from other AWS services or your own apps.

Cold starts: the elephant

When Lambda spins up a new container (first invocation, or after idle), the runtime + your code load. That's a cold start: 100-500 ms for Node/Python, 1-5s for Java. Subsequent invocations on a warm container are sub-10ms. Mitigations: keep code small; lazy-load big modules; pin a SDK client outside the handler (shared across warm invocations); use Provisioned Concurrency (pre-warmed instances; costs money). For interactive workloads (API), cold starts are real UX. For async (queue consumers), usually fine.

When NOT to use Lambda

Long-running jobs (> 15 min). Use Fargate or batch services. Heavy CPU or GPU. EC2 or specialised instances are cheaper per second of work. Stateful workloads needing local disk. Lambda has 512MB-10GB /tmp; ephemeral. Sub-10ms latency requirements. Cold starts blow that budget. Apps with thousands of concurrent users where you'd pay less for always-on capacity.

Common mistakes only experienced engineers avoid

Initializing the AWS SDK client inside the handler. Cold-start hit on every invocation. Move OUTSIDE the handler to share across invocations. Forgetting timeouts. Default is 3 seconds; many functions need longer. Set explicitly. No DLQ (dead-letter queue) on async invokes. Failed events silently dropped. Lambda + RDS without a connection pooler. Hits Postgres max_connections fast. Use RDS Proxy. Mounting deps in the deploy zip. Use Layers for shared dependencies across functions.

Quick Check

Where should you initialize an AWS SDK client in a Lambda function?

Pick the best practice.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←RDS
Back to Cloud Platforms — AWS
VPC→