CLD110 · Module 6 — Compute Services

AWS Lambda

Run code without provisioning or managing servers
Lambda Serverless Event-driven FaaS
Mesa Community College · AWS Academy

What is AWS Lambda?

Lambda is a Function as a Service (FaaS). You write a function, upload it, and AWS runs it in response to events — with no servers to manage, ever.

What you provide
  • Your function code (the handler)
  • Runtime (Python, Node.js, Java, Go…)
  • Memory allocation (128 MB – 10 GB)
  • Timeout (up to 15 minutes)
  • IAM execution role
What AWS provides
  • Servers, OS, runtime environment
  • Automatic scaling (one invocation to millions)
  • High availability across AZs
  • Execution logs to CloudWatch
  • Built-in fault tolerance

Key insight: Lambda scales to zero when there are no events. You pay only for the milliseconds your code actually runs — not for idle time.

Event-driven execution

Lambda functions are triggered by events. An event is any signal from an AWS service or external source that invokes your function.

Lambda event triggers and outputs Multiple AWS services can trigger Lambda: API Gateway for HTTP requests, S3 for object events, DynamoDB Streams for table changes, EventBridge for scheduled or custom events, and SQS for queue messages. Lambda processes the event and can write to DynamoDB, S3, SNS, or other downstream services. λ Lambda your function code API Gateway Amazon S3 DynamoDB Streams EventBridge / SQS DynamoDB / RDS Amazon S3 SNS / SQS Another Lambda Triggers (event sources) Downstream services

Lambda limits and constraints

Lambda's serverless model trades flexibility for simplicity. Knowing the limits helps you design correctly.

Hard limits

  • Max execution time: 15 minutes per invocation
  • Memory: 128 MB – 10,240 MB (scales CPU proportionally)
  • Deployment package: 50 MB zipped, 250 MB unzipped
  • Ephemeral storage (/tmp): 512 MB – 10 GB
  • Concurrent executions: 1,000 per region (default; can be raised)

Design implications

  • Not suitable for long-running jobs (>15 min) — use Fargate or EC2 Batch
  • Functions must be stateless — don't rely on local disk between invocations
  • Cold starts add latency — mitigate with Provisioned Concurrency
  • No persistent connections — use RDS Proxy for database access

Lambda pricing

Lambda has one of the most granular pricing models in AWS — you pay for exactly what you use.

Two billing dimensions
  • Number of requests — first 1 million requests per month are free; $0.20 per million after
  • Duration — charged per GB-second (memory × time). First 400,000 GB-seconds free per month.

Duration is rounded to the nearest 1 ms.

Example calculation

Function: 512 MB memory, runs for 200 ms, invoked 1 million times/month


  • Requests: 1M — free tier covers it
  • Duration: 0.5 GB × 0.2 s × 1,000,000 = 100,000 GB-s
  • 100,000 GB-s ÷ 400,000 free = within free tier

Cost: $0.00 for this example

Free tier is permanent (not just the first year): 1M requests and 400,000 GB-seconds per month, every month, on every AWS account.

Common Lambda use cases

API backends

API Gateway + Lambda = a fully serverless REST or GraphQL API.


No web server to run — each HTTP request is one function invocation.

File processing

Trigger on S3 upload: resize images, transcode video, parse CSV, virus scan.


Process thousands of files in parallel instantly — each file triggers one Lambda.

Scheduled tasks

EventBridge cron rule triggers Lambda on a schedule — replace cron jobs entirely.


No server to keep running just to run a script once an hour.

Stream processing

Process records from Kinesis or DynamoDB Streams in real time.

Automation / ops

React to CloudWatch alarms, Config rule violations, or Security Hub findings automatically.

Edge compute

Lambda@Edge runs functions at CloudFront edge locations — near the user, before the origin.

Lambda vs Fargate vs EC2

Dimension AWS Lambda AWS Fargate Amazon EC2
Unit of work Function invocation Container task Running instance
Max duration 15 minutes Hours / days Unlimited
Scales to zero Yes Yes No (must stop instance)
Cold start latency Possible (ms–seconds) Possible (seconds) None (already running)
State / storage Stateless only Ephemeral or EFS Full EBS persistence
Pricing model Per ms of execution Per second of task Per second of instance

Key takeaways

  • Lambda = FaaS — upload a function, define a trigger, AWS runs it at any scale
  • Event-driven — Lambda runs only when triggered; it scales to zero between events
  • 15-minute limit — Lambda is for short, discrete tasks, not long-running processes
  • Stateless by design — don't store state in function memory between invocations
  • Permanent free tier — 1M requests + 400K GB-seconds free every month
The mental model

Lambda is a vending machine for compute. Drop in an event, get back a result. You never think about the machine itself.

Use Lambda for event-driven, short-duration tasks. Use Fargate for longer-running containerized workloads. Use EC2 when you need persistent, always-on compute.

Review questions

Recall
  • What is the maximum execution duration for a Lambda function?
  • What service model does Lambda represent — IaaS, PaaS, or FaaS?
  • What are the two billing dimensions for Lambda?
  • Why must Lambda functions be stateless?
Apply
  • A user uploads a photo to an S3 bucket and the app needs to generate a thumbnail immediately. Which AWS compute service is the best fit?
  • A job needs to process a 2-hour video transcode. Is Lambda appropriate? What should you use instead?
  • Your team wants an API with no servers to manage and pay-per-request billing. What combination of services would you use?

Next: Amazon EKS — Kubernetes as a managed service. How does container orchestration work at the level above ECS?