With EC2 you rent a server and keep it running. With AWS Lambda you upload a function, and AWS runs it only when something triggers it. There is no server to patch, and you pay per request and per millisecond of run time. This model is called serverless.
How Lambda works
You write a handler function in Python, Node.js, Java or another supported language:
def lambda_handler(event, context):
name = event.get("name", "learner")
return {"statusCode": 200, "body": f"Hello, {name}"}
The event contains the input from whatever triggered the function.
Common triggers
- API Gateway: turn a function into an HTTP API endpoint.
- S3: run code when a file is uploaded, such as resizing an image or processing a CSV.
- EventBridge schedules: run a job every night, like a cron job without a server.
- SQS and DynamoDB streams: process messages and data changes.
Limits to know
- A maximum run time of 15 minutes per invocation.
- Memory from 128 MB to 10 GB; CPU grows with memory.
- Cold starts: the first request after a quiet period is slower while AWS prepares the environment.
- Functions are stateless: store data in S3, DynamoDB or RDS, not on local disk.
Permissions
Every function runs with an IAM execution role. Give it only the permissions it needs, such as reading one S3 bucket, and nothing more.
When to use Lambda, and when not
Lambda suits event-driven tasks, small APIs and scheduled jobs with uneven traffic. Long-running processes, very steady heavy traffic, or apps needing persistent connections may be cheaper and simpler on EC2 or containers.
A first exercise
Create a function that runs when a CSV is uploaded to an S3 bucket, counts its rows, and writes the result to CloudWatch Logs. Stay within the free tier, and delete test resources afterwards.
Related: AWS S3 for beginners, AWS IAM explained and AWS RDS for beginners.
Hands-on labs like this are part of our AWS and DevOps course in Bangalore.
Book a free demo class at our BTM Layout centre, and ask a counsellor for batch details.

AWS CloudWatch Basics: Logs, Metrics and Alarms - ScholarLogic
[…] AWS Lambda for beginners, AWS EC2 and AWS […]