"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)