Ravi Sir's Cards › AWS › Lambda serverless compute
AWS Lambda serverless compute: functions, triggers, limits and your first function
This page keeps the related Lambda cards on one topic page, so you can revise serverless compute in one sitting. It has the ten cards from “What is AWS Lambda? Serverless explained with examples” and the eight cards from “Create your first AWS Lambda function step by step”. Those are the first two packs in the hub’s Lambda, API Gateway and DynamoDB group (80 cards in total). Later packs (triggers in more depth, API Gateway, and DynamoDB) can be their own topic pages later.
Each card still has its image and its original text. Under each group you will also find a short Why, What, How example, and an exam tip, in easy English. The names, function names and order numbers in the stories are made up for learning. Limits and free-tier numbers below come from these live cards; always re-check the AWS Lambda documentation, because they can change.
What is AWS Lambda, and when to use it
Why this matters
A bakery that stays open all night with no customers still pays rent. An EC2 instance that sits idle is billed the same way: you pay while the server runs. Many labs only need a short function when an event happens.
What it is
AWS Lambda runs your code only when an event happens. You upload the function; AWS runs it, scales it, and patches the platform. You pay per request and for duration (memory setting times time, in GB-seconds), not for idle hours. Three words must stay clear: the function is your code, the trigger is what starts it, and the event is the JSON payload it receives. Serverless does not mean no servers. It means AWS owns the servers, the patching and the capacity. These cards give the hard caps they teach in the lab: timeout max 15 minutes, memory 128 MB to 10,240 MB, zip upload 50 MB and unzipped package 250 MB, and a free tier of about 1 million requests and 400,000 GB-seconds per month. Use Lambda for short event-driven work. Use EC2 or containers (ECS/EKS) for work past 15 minutes, GPUs, a special OS, or a long-running service.
How it works — a real example
Suppose a photo is uploaded to an S3 bucket. A Lambda function starts, writes a thumbnail, and then sits idle — you are not paying for an always-on server. If the next job is a 15-minute video encode, these cards say to use EC2 or ECS instead, because of the Lambda timeout. The bucket and file names are made up for learning.
Common mistake / exam tip
The execution role is the IAM role the function assumes so it can call AWS APIs. Without it, even CloudWatch Logs writes fail. Attach a basic execution role first, then add only the S3 or DynamoDB actions you need. Idle time is not billed like EC2, but a cold start still counts as duration. If a workload needs hours, a GPU, or a custom kernel, do not force it into Lambda.
What is AWS Lambda?
Read card text
What this card says
Why do we need it?
A bakery open all night with no customers still pays rent. Always-on servers waste money the same way.
What is it?
Lambda runs your code only when an event happens. You pay for requests and duration, not idle hours.
How to do it
Write a small function, set a runtime and role, then add a trigger (S3, API Gateway, schedule…). Lambda › Create function
Example
Photo uploaded to S3 → Lambda makes a thumbnail in seconds → idle again.
Function, trigger and event
Read card text
What this card says
Why do we need it?
Three words sound the same in class. Clear names stop confusion in the console.
What is it?
Function = your code. Trigger = what starts it. Event = the JSON payload it receives.
How to do it
Open any function → Configuration → Triggers. Test with a sample event JSON. Test › hello-world
Example
API Gateway POST /orders → Lambda gets method, path and body in the event.
Lambda vs EC2 vs containers
Read card text
What this card says
Lambda
Use an event-driven function for bounded work. On-demand Event Functions can run up to 30 minutes per invocation.
EC2 and containers
EC2 gives OS control. ECS and EKS manage container workloads, including services that keep running.
Example
Resize an image on upload with Lambda. Run a continuous worker, GPU task or hours-long job on a suitable worker platform.
Lambda limits and cost
Read card text
What this card says
On-demand Event Functions
Configure up to 1,800 seconds (30 minutes), and 128–10,240 MB memory. Check the trigger and account quotas separately.
Package size
A ZIP upload via console or API has a 50 MB compressed limit. Unzipped contents including layers are limited to 250 MB.
Costs
A 256 MB function running for one second uses 0.25 GB-seconds. Check request charges, duration, the current allowance, and connected services.
Comparison: Who manages the server?
Read card text
What this card says
AWS Lambda
You upload code; AWS runs and scales it.
Amazon EC2
You pick, patch and size a virtual server.
Key points
Pay per request and duration. Pay while the instance runs, even idle.
Example
Thumbnail on S3 upload.
Use when
Short event-driven work. Long jobs, special OS, GPUs.
Comparison: Lambda vs containers
Read card text
What this card says
Lambda packaging
A Lambda Event Function accepts a ZIP or container image and runs per event. The on-demand invocation limit is 30 minutes.
Container services
ECS or EKS can manage long-running services and workers. A Lambda image still follows Lambda runtime and invocation limits.
Choose by workload
Pick a bounded event handler for Lambda. Consider a service or worker for long-lived processes and custom runtime needs.
Interview: What does serverless mean if servers still exist?
Read card text
What this card says
What it is
Servers still run your code, but AWS owns patching, scaling and capacity.
Why it matters
You focus on functions and events, not OS updates at 2 AM.
How / example
Example: Lambda scales with S3 uploads; you never SSH to add boxes.
Interview: When would you choose EC2 over Lambda?
Read card text
What this card says
Lambda fit
Use an on-demand Event Function for bounded events up to 30 minutes. Validate the trigger's own limits.
EC2 fit
Choose EC2 or another worker platform for GPU jobs, custom OS needs, or tasks that outlast the suitable Lambda invocation mode.
Example
For an hours-long GPU training job, Lambda can accept a request and start a separate job. Return a job ID and report progress separately.
Interview: What is a Lambda execution role?
Read card text
What this card says
What it is
An IAM role the function assumes so it can call AWS APIs.
Why it matters
Without it, even CloudWatch Logs writes fail. Least privilege to only needed actions.
How / example
Attach AWSLambdaBasicExecutionRole first; add S3/DynamoDB policies only if needed.
Interview: How is Lambda billed?
Read card text
What this card says
What it is
Per request plus GB-seconds: memory setting × duration.
Why it matters
Idle time is not billed like EC2. Cold starts still count as duration.
How / example
Raise memory if CPU-bound; wall time often drops and can cost less.
Create and test your first Lambda function
Why this matters
Reading a definition is not enough. One working function in the console builds confidence, and a few console habits stop “it still runs the old code” bugs.
What it is
In the console you choose Author from scratch, then a name, a runtime, an architecture, and an execution role. Common managed runtimes include Python, Node.js, Java, .NET and Go. One function uses one runtime. The handler has two main arguments: event (the payload) and context (metadata such as the request id and remaining time). Environment variables hold non-secret config such as a table name. Memory also buys CPU: raising memory does not only add RAM. Timeout stops a runaway invoke. Test events are saved sample JSON, and print or console.log goes to CloudWatch Logs under /aws/lambda/<name>. Prefer the execution role over access keys in code or environment variables.
How it works — a real example
Suppose we create hello-lab in the console, deploy a handler that returns {"ok": true}, and click Test with a blank {}. We then set TABLE_NAME=lab-notes as an environment variable, and we watch the latest log stream for a line such as order=42. If a call needs about 5 seconds, a 3-second timeout will fail; the lab card uses a 10-second timeout for that API example. The names and order numbers are made up for learning.
Common mistake / exam tip
The console editor can save a draft, but invokes run the last deployed version. After you edit code, click Deploy, then Test. Skipping Deploy makes the function look “stuck” on old code. Never commit AKIA… keys in the function. If a handler is CPU-bound, benchmark more memory (for example 256 MB versus 1024 MB) and pick the cheaper GB-seconds result, because more memory also adds CPU and the function may finish faster.
Create a function in the console
Read card text
What this card says
Why do we need it?
Reading docs is not enough. One working function builds confidence.
What is it?
Author from scratch: name, runtime, architecture, execution role.
How to do it
Lambda › Create function › Author from scratch › create › Deploy after edits. Create function
Example
hello-lab returns {"ok": true}. Click Test with a blank {}.
One idea, many runtimes
Read card text
What this card says
Why do we need it?
Teams speak different languages. The same event shape works across them.
What is it?
Python, Node.js, Java, .NET and Go are common managed runtimes. One function = one runtime.
How to do it
Clone the lab in a second runtime; keep the handler contract the same. handler(event, context)
Example
Python uses def handler(event, context). Node uses exports.handler = async (event) => ….
Test events and CloudWatch Logs
Read card text
What this card says
Why do we need it?
Broken JSON in production is painful. Test first with a saved event.
What is it?
Test events are sample JSON. print/console.log goes to CloudWatch Logs.
How to do it
Test tab → create event → invoke. Then Monitor › View CloudWatch logs. /aws/lambda/name
Example
Log line "order=42" appears in the latest stream within seconds.
Env vars, memory and timeout
Read card text
What this card says
Why do we need it?
Hard-coded table names break when you move from lab to prod.
What is it?
Environment variables hold non-secret config. Memory also buys CPU. Timeout stops runaway work.
How to do it
Configuration › Environment variables; General configuration for memory/timeout. TABLE_NAME=lab-notes
Example
Timeout 3 s fails a 5 s call. Set 10 s for the API lab.
Interview: What are the two main handler arguments?
Read card text
What this card says
What it is
event (payload) and context (metadata: request id, remaining time).
Why it matters
Business data lives in event; timeouts and logging use context.
How / example
context.get_remaining_time_in_millis() helps abort early.
Interview: Why must you click Deploy after editing code?
Read card text
What this card says
What it is
The console editor saves a draft; invokes run the last deployed version.
Why it matters
Skipping Deploy makes tests look "stuck" on old code.
How / example
Edit → Deploy → Test. Same habit for aliases later.
Interview: Why prefer an IAM role over access keys in Lambda?
Read card text
What this card says
What it is
Roles give temporary credentials; keys in code or env can leak.
Why it matters
Rotation and least privilege are easier with roles.
How / example
Never commit AKIA… keys; attach policies to the execution role.
Interview: Does raising memory only buy RAM?
Read card text
What this card says
What it is
No — Lambda allocates more CPU as memory rises.
Why it matters
CPU-bound handlers often finish faster at higher memory.
How / example
Benchmark 256 vs 1024 MB; pick the cheaper GB-s result.
FAQ
What does serverless mean if servers still exist?
Servers still run your code, but AWS owns patching, scaling and capacity. You focus on the function and the event, not on SSH or OS updates.
What is the difference between a function, a trigger and an event?
The function is your code. The trigger is what starts it (S3, API Gateway, a schedule, and so on). The event is the JSON payload the function receives.
When should I choose EC2 or containers instead of Lambda?
When the work can run longer than 15 minutes, or you need GPUs, a custom kernel, sticky local state, or a long-running service. Lambda is for short event-driven work.
How is Lambda billed?
Per request plus GB-seconds (the memory setting multiplied by duration). Idle time is not billed like EC2. A cold start still counts as duration. Check current AWS pricing when you practise, because prices change.
What limits do these cards teach?
Timeout max 15 minutes. Memory 128 MB to 10,240 MB. Zip upload 50 MB; unzipped package 250 MB. Free tier: about 1 million requests and 400,000 GB-seconds per month. Re-check the official Lambda documentation, because limits can change.
What is a Lambda execution role?
An IAM role the function assumes so it can call AWS APIs. Without it, even CloudWatch Logs can fail. Give only the actions you need. Do not put long-lived access keys in the function.
Why must I click Deploy after I edit code in the console?
The editor can save a draft, but Test and other invokes run the last deployed version. Edit, Deploy, then Test.
Does raising memory only buy more RAM?
No. Lambda also allocates more CPU as memory rises. A CPU-bound handler often finishes faster at a higher memory setting, and the GB-seconds cost may even drop. Benchmark before you decide.
Related lessons
These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):