Setting Up First AWS Lambda Function

If you have ever wanted to run code without worrying about servers, AWS Lambda is the way to go. Lambda is a serverless computing services that lets you execute your code in response to various events, without having to manage any infrastructure. In this blog post, we will guide you through the process of setting up first Lambda function. Whether you are deploying it via the AWS console, the AWS CLI, or infrastructure as Code(IaC), we will cover everything you need to know. plus, we will look at some cool triggers that make your Lambda function even more powerful.
STEP 1: Create an AWS Account and get familiar with the Lambda console
Sign up for AWS: Head over to AWS’s official website and create an account. You’ll need a credit card, but don’t worry, there’s a free tier for new users to get started without a hefty bill.
Navigate to Lambda: Once your account is ready, sign in to the AWS Management Console. Type “Lambda” into the search bar, and select it from the results. This takes you to the Lambda dashboard, where you can create, manage, and deploy Lambda functions.
STEP 2: Write Your Lambda Function(“ Hello World”)
- Writing a simple function is the best way to start. Let’s go with the classic “Hello World“ to keep it easy.
- Create a new function:
Click on create function.
choose Author from scratch.
Give function a name, like HelloworldFunction.
Pick Python (or any language you are comfortable with) for the runtime.
Select an execution role for your Lambda function. If you don’t have one, you can let AWS create a basic one for you with the default permissions.
2. Write the Code:
Once the function is created, you’ll land in the inline code editor.
- Save Your Function:
- Once your code is ready, click Deploy to save your function. Congratulations! You’ve just written your first Lambda function.
Step 3: Deploying Your Lambda Function
Using the Console (The Simple Way)
The AWS Console is the easiest and quickest way to deploy a Lambda function. After creating your function in the Lambda console, all you need to do is hit the Deploy button. This method is ideal when you’re just getting started and want to quickly test things.
Step 4: API Gateway
Want to trigger your Lambda function via HTTP requests? API Gateway is the way to go. You can easily set up an API that calls your Lambda function when a user hits an endpoint.
Go to API Gateway in the AWS Console.
Create a new REST API and define a resource (e.g.,
/hello
).Set up an HTTP method (like
GET
) to trigger your Lambda function.
After that, you’ll have an API endpoint that, when hit, will execute your Lambda function!
Now that your Lambda function is ready, let’s set up an API Gateway to trigger it via an HTTP request. This will allow you to call your Lambda from a web browser, Postman, or any frontend app. First, head over to the API Gateway service in the AWS Console and start creating a new API. Select REST as the protocol and choose to create a New API. Give your API a name (like "MyAPI") and leave the endpoint type as Regional. Once you’ve filled in the details, click Create API — just like in the screenshot below:
Once your API is created, it's time to connect it to your Lambda function. In this step, we define the method execution flow — essentially, how your API Gateway request is routed to your Lambda function and what kind of response it returns. The diagram below shows the full lifecycle of a GET
request: starting from the client, passing through the Method Request, Integration Request, and finally reaching the Lambda function. The response then flows back through the Integration Response and Method Response before returning to the user.
Time to test it all out! Head back to the API Gateway console and hit the Test button under your method. If everything’s set up correctly, you’ll see a successful response — just like this! The response shows a statusCode: 200
and the body returns our classic message: "Hello from Lambda!". Congrats, your first serverless API is live and responding!
Before your API can go live and be accessible via a public URL, it needs to be deployed to a stage. Think of a stage like an environment—such as dev
, test
, or prod
—that helps you manage different versions of your API. In this step, we’re creating a new deployment stage named dev, which will generate an endpoint URL we can use to invoke our Lambda function. Just fill in the details and click Deploy:
Voila! 🚀 Your API is now successfully deployed to the dev
stage. The blue highlighted Invoke URL
Now that the deployment is complete, you’ll receive a unique Invoke URL for your API stage. This URL is your live endpoint—hitting it in the browser or via tools like Postman or curl
will invoke the connected Lambda function and return its output (in our case, "Hello from Lambda!"
). This confirms that your API Gateway and Lambda integration is working perfectly!
Wrapping Up: Your First Serverless API is Live!
And just like that, you've taken your first step into the serverless future! You've built and deployed a fully functional API using Amazon API Gateway and AWS Lambda, without managing a single server.
Whether you're building a microservice, a webhook handler, or the next unicorn startup, this foundation sets you up to scale, iterate, and deploy with confidence.
Next Steps:
Add more HTTP methods (POST, PUT, DELETE)
Connect your Lambda to DynamoDB or S3
Secure your endpoint with API keys or Cognito
Monitor and log with CloudWatch
Stay curious, keep building, and remember:
With AWS, your backend is just a Lambda away.
"As we dive deeper into AWS Lambda’s capabilities—from runtime support to secure configurations—one thing becomes clear: building smart, scalable, and secure serverless applications has never been more within reach."
Subscribe to my newsletter
Read articles from Maitry Patel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
