DEV Community

andrewesley1211
andrewesley1211

Posted on

Building a serverless function in AWS

🧱 What I Built
I created a simple Lambda function that returns a message like:
Hello, Andre! Your serverless function is working.

The function runs instantly when someone hits the API URL. No servers. No maintenance. Just code.

🪜 Step-by-Step: Building the Serverless Function

  1. Open AWS Lambda
  2. Log in to AWS
  3. Search for Lambda
  4. Click Create function
  5. Create the Function
  6. Choose Author from scratch
  7. Name: myServerlessFunction
  8. Runtime: Node.js 20.x
  9. Leave everything else as default
  10. Click Create function
  11. Add the Code Replace the default code with this:

export const handler = async (event) => {
const name = event.queryStringParameters?.name || "World";

return {
statusCode: 200,
body: JSON.stringify({
message: Hello, ${name}! Your serverless function is working.,
}),
};
};

Click Deploy.

  1. Add an API Gateway Trigger This makes your function accessible through a URL.
  2. Scroll to Function overview
  3. Click Add trigger
  4. Choose API Gateway
  5. Select Create a new API
  6. API type: HTTP API
  7. Security: Open
  8. Click Add AWS will generate a public endpoint URL.
  9. Test the Function Open the URL in your browser:

Got my result at below link
https://yz179ik8xe.execute-api.us-east-2.amazonaws.com/default/myServerlessFunction

🧠 What I Learned
Building this project helped me understand:

  • How AWS Lambda works
  • How serverless functions scale automatically
  • How API Gateway exposes functions through HTTP endpoints
  • How to pass query parameters into a Lambda function
  • How to deploy backend logic without provisioning servers This is a great beginner project because it teaches the fundamentals of serverless architecture without overwhelming complexity.

Top comments (0)