DEV Community

Yash Sonawane
Yash Sonawane

Posted on

How to Create Your First Lambda Function (No DevOps Needed) โšก๐Ÿง‘โ€๐Ÿ’ป

"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;
};
Enter fullscreen mode Exit fullscreen mode

Click Deploy to save the code.


๐Ÿงช Step 4: Test It

1. Click โ€œTestโ€ > โ€œConfigure test eventโ€

  • Event name: TestHello
  • JSON input:
{
  "name": "Yash"
}
Enter fullscreen mode Exit fullscreen mode

2. Click Test again โ€” and boom ๐Ÿ’ฅ

You should get:

"Hello, Yash! ๐Ÿ‘‹"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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)