"Wait โ you're telling me I can run backend code without servers, setup, or infrastructure?"
Yup. Thatโs the magic of AWS Lambda โ and you donโt need to be a DevOps ninja to get started.
In this beginner-friendly guide, weโll walk through how to create, test, and run your first Lambda function step-by-step. No EC2. No containers. Just code + click = ๐
๐ง What is AWS Lambda (in Plain English)?
AWS Lambda is serverless computing โ which means you write code, upload it, and AWS runs it for you only when needed.
๐ก Real-life analogy: Think of Lambda as a vending machine. You put in the code (your snack), and it serves it only when someone requests it โ no kitchen, no chef, no electricity bill unless itโs used.
You donโt manage servers, worry about scaling, or pay when it's idle. It's perfect for microtasks, APIs, or automating workflows.
๐ฏ What You'll Build
We'll build a simple Lambda function that:
- Takes a name as input
- Returns a greeting like:
"Hello, Dev! ๐"
You can trigger it manually or hook it into an API later.
๐ Step-by-Step: Create Your First Lambda Function
1. Head to the AWS Lambda Console
https://console.aws.amazon.com/lambda
Click โCreate Functionโ.
2. Choose "Author from scratch"
-
Function name:
helloLambda -
Runtime:
Node.js 18.x(or choose Python 3.11 if you prefer) - Permissions: Create a new role with basic Lambda permissions
Click โCreate Functionโ.
โ๏ธ Step 3: Write the Code
In the Function code editor, replace everything with:
exports.handler = async (event) => {
const name = event.name || "Dev";
const response = {
statusCode: 200,
body: JSON.stringify(`Hello, ${name}! ๐`),
};
return response;
};
Click Deploy to save the code.
๐งช Step 4: Test It
1. Click โTestโ > โConfigure test eventโ
-
Event name:
TestHello - JSON input:
{
"name": "Yash"
}
2. Click Test again โ and boom ๐ฅ
You should get:
"Hello, Yash! ๐"
Congrats! ๐ Youโve just run your first cloud function, serverless and instant.
๐ Bonus: Trigger Lambda with API Gateway
Want to call this from a frontend app or Postman?
1. Add Trigger > API Gateway
- Choose HTTP API
- Enable Open access (for testing only โ use auth in prod)
2. Click the API endpoint and try it:
curl -X POST https://your-api-id.amazonaws.com/default/helloLambda \
-d '{"name": "Dev"}' \
-H "Content-Type: application/json"
Youโve now got a working backend API โ with no infrastructure. ๐งโโ๏ธ
โ๏ธ Real-World Use Cases for Lambda
- ๐งผ Image resizing after S3 upload
- ๐ Send email notifications
- ๐งพ PDF generation on-demand
- ๐ค Cron jobs for data cleanup
- ๐ฉ Slack bot commands
- โก Lightweight backend for React apps
๐ก Tips for Beginners
- Use CloudWatch Logs for debugging
- Keep function under 15 minutes runtime
- Keep code simple and stateless
- Use environment variables for secrets/config
๐ง Recap
| Step | What You Did |
|---|---|
| 1๏ธโฃ | Created a Lambda function from scratch |
| 2๏ธโฃ | Wrote a greeting function in Node.js |
| 3๏ธโฃ | Tested it with sample input |
| 4๏ธโฃ | Optionally hooked it to an API Gateway |
Thatโs it โ youโre now officially a serverless dev! โ๏ธโก
๐ฌ Letโs Connect!
Was that easier than you thought?
What do you want to build next with Lambda โ an email bot, an image converter, or something wild?
๐ Drop your ideas in the comments, hit โค๏ธ if this helped you, and share this with your serverless-curious friends!
Letโs keep building โ one function at a time. ๐งก
Top comments (0)