100 Days of AWS – Day 12: Your First Look at Serverless with AWS Lambda
Welcome to Day 12! We're wrapping up Core Compute week by jumping into one of the most transformative concepts in the cloud: serverless computing with AWS Lambda.
The Question
A developer needs to run a function that automatically resizes an image every time a new file is uploaded to an S3 bucket. They want a solution that only runs when needed and where they only pay for the exact time the code is running.
Which AWS service is purpose-built for this kind of event-driven, serverless task?
The Correct Answer
The correct answer is (C) An AWS Lambda function.
Why It's Correct: Run Code, Not Servers
AWS Lambda is a serverless, event-driven compute service, also known as Function as a Service (FaaS). Let's break that down:
- Serverless: You never have to provision, patch, or manage any servers. AWS handles all the operational and administrative tasks for you.
- Event-Driven: Your code (called a "function") doesn't run continuously. Instead, it sits idle until it is triggered by an event. In our scenario, the "event" is a new image being uploaded to an S3 bucket.
- Pay for Value: You are billed only for the time your code is actually executing, measured in milliseconds. You never pay for idle time, making it extremely cost-effective for workloads that aren't running constantly.
The scenario in the question is the classic, textbook use case for AWS Lambda.
A Simple Analogy: Owning a Car vs. Taking a Taxi 🚕
- EC2 is like owning a car. It's parked in your garage, ready to go 24/7. You pay for the car, insurance, and maintenance, even when you aren't driving it.
- Lambda is like taking a taxi (or a ride-share). You only call for it when you need to go somewhere. You pay only for that specific trip and don't worry about the car's maintenance, fuel, or parking.
Analysis of the Incorrect Options
- (A) A script on an EC2 instance: This would require a server to be running 24/7. It would be inefficient and costly, as you'd pay for the server even when no images are being uploaded.
- (B) An Elastic Beanstalk worker environment: This is a Platform as a Service (PaaS) designed to run long-running applications or background tasks. It's still server-based and is overkill for a simple, short-lived function.
- (D) A container on Amazon ECS: Amazon ECS is a powerful container orchestration service. While you could build a container to perform this task, it's far more complex to set up and manage than a simple Lambda function, which is designed precisely for this kind of lightweight, event-driven job.
Further Reading
Official AWS Documentation:
What is AWS Lambda?
Keywords
- AWS Lambda
- Serverless Computing
- Function as a Service (FaaS)
- Event-Driven Architecture
- S3 Events
- Pay-per-execution
- Stateless Functions
- API Gateway
- Serverless Framework
- Cold Start
- Concurrency
- "what is aws lambda used for"
- "aws lambda vs ec2 for backend"
- "how to trigger a lambda function from s3"
- "benefits of serverless computing"
- "aws lambda pricing model explained"
0 Comments