AWS Lambda Tutorial: Creating Your First Lambda Function

Advertisement

Jun 18, 2025 By Tessa Rodriguez

If you're stepping into serverless computing, AWS Lambda is likely the name you've come across a few times already. And if you're wondering whether it's as flexible and lightweight as they say, it is. At its core, Lambda is about running code without worrying about the infrastructure underneath. You write the function, deploy it, and AWS handles the execution. Simple in theory, yet there's a process that requires a bit of walking through.

Let’s break down how to create your very first Lambda function, step by step. No assumptions, no skipping over the essentials. Just a clear, complete walkthrough you can rely on.

What Is AWS Lambda (And Why It Matters)

Before diving into the console, it's important to understand what exactly you're dealing with. AWS Lambda is a compute service from Amazon Web Services that runs your code in response to events and automatically manages the computing resources. You don't have to manage servers. You don't have to configure scaling policies. In fact, you don’t even have to think about provisioning capacity.

In other words, Lambda gives you efficiency with minimal overhead. That’s its real strength.

Step 1: Setting Up the Basics

Before you write a single line of code, there’s some groundwork that needs to be done. Nothing complex—just the initial setup that ensures you're ready to go.

Sign in to the AWS Console

Start by logging into the AWS Management Console. If you don’t already have an AWS account, you’ll need to create one. Once signed in, navigate to the Lambda service using the search bar at the top.

Region Selection

Choose your preferred region in the upper-right corner of the console. Lambda functions are region-specific, so any resources you connect later (like an S3 bucket or an API Gateway) should ideally reside in the same region.

IAM Role (Execution Role)

AWS Lambda needs permission to execute functions on your behalf. This is handled through an IAM role—specifically, an execution role. When creating your Lambda function, AWS can generate this role for you with basic permissions. For now, that’s all you need.

Step 2: Creating the Function

With the prep done, it’s time to actually create the Lambda function. AWS gives you multiple options: authoring from scratch, using a blueprint, or importing from a container image. For your first time, it’s best to start from scratch.

Navigate to “Create Function”

Once you're in the Lambda console, click Create Function. You’ll be presented with a form to configure your new function.

Fill in the Details

  • Function name: Give your function a meaningful name like HelloWorldLambda.
  • Runtime: Choose your language. For this tutorial, let’s go with Python 3.12.
  • Permissions: Choose "Create a new role with basic Lambda permissions." This sets up an IAM role that allows your function to write logs to Amazon CloudWatch.

Click the Create function. AWS will take a few seconds to set things up.

Step 3: Writing the Code

Now comes the part where you actually write your function. AWS gives you a built-in editor inside the console for quick scripts and testing.

Basic Hello World Function

By default, AWS inserts a basic handler function for you. If it’s not already there, replace the code in the editor with this:

def lambda_handler(event, context):

return {

'statusCode': 200,

'body': 'Hello from Lambda!'

}

This is your function. The event parameter holds the incoming request data, and context gives you metadata about the invocation. In this case, the function simply returns a 200 response and a short message.

Click Deploy once you're done editing. This saves the function code and makes it ready for execution.

Step 4: Testing the Function

You now have a function. It's deployed and ready to run. But how do you know it works? AWS makes that part pretty easy, too.

Create a Test Event

Click the Test button at the top. You’ll be prompted to configure a test event.

  • Event name: Call it something like TestEvent1.
  • Template: Leave the default hello-world JSON, or input your own event data if you like.

Click Create, then hit Test again to run your function.

View the Results

After running the test, the execution result will appear at the top of the console. You should see a response similar to:

{

"statusCode": 200,

"body": "Hello from Lambda!"

}

You’ll also see logs from the execution below, showing duration, memory used, and log output. This is useful when you're troubleshooting or optimizing performance later on.

Step 5: Adding a Trigger (Optional But Worth It)

Right now, your function exists, and you can test it manually. But Lambda really shines when it's connected to an actual event source. For instance, you can make it respond to an HTTP request or a file upload.

Let’s wire it up to API Gateway, so your Lambda can be triggered through a browser or HTTP client.

Add API Gateway as a Trigger

  • From your Lambda function’s page, click Add trigger.
  • Choose API Gateway.
  • Select Create an API, then HTTP API.
  • Leave the security as Open (for testing purposes—don’t use this for production).
  • Click Add.

You’ll get an API endpoint URL that you can now open in a browser or run using curl. When you hit it, the Lambda function will execute and return the message.

Step 6: Viewing Logs in CloudWatch

Each time your Lambda function runs, it sends logs to Amazon CloudWatch automatically. These logs are valuable for tracking execution details, error messages, and anything you print() inside your function.

To see the logs:

  • Go to the Monitoring tab of your function.
  • Click View logs in CloudWatch.
  • Select the latest log stream.

Here you’ll find timestamps, request IDs, and any messages from your function’s execution. It’s clean, structured, and extremely helpful for debugging.

Wrapping Up

Creating your first Lambda function isn’t complicated, but it does follow a specific flow. You start with a basic setup, define your function, deploy it, test it, and (optionally) link it to a trigger. That’s all there is to it. The real magic of Lambda unfolds when you start chaining it with other AWS services. But even at the simplest level, it delivers on its promise: code execution without servers to manage.

Advertisement

You May Like

Top

AWS Lambda Tutorial: Creating Your First Lambda Function

Curious how to build your first serverless function? Follow this hands-on AWS Lambda tutorial to create, test, and deploy a Python Lambda—from setup to CloudWatch monitoring

Jun 18, 2025
Read
Top

How to Handle Missing Dates in Time Series Data Using Python

Learn how to impute missing dates in time series datasets using Python and pandas. This guide covers reindexing, filling gaps, and ensuring continuous timelines for accurate analysis

Jun 15, 2025
Read
Top

5 Exciting Python Libraries to Watch in 2025

Looking for the next big thing in Python development? Explore upcoming libraries like PyScript, TensorFlow Quantum, FastAPI 2.0, and more that will redefine how you build and deploy systems in 2025

Jun 18, 2025
Read
Top

How to Use Google Mediapipe Tasks API for Easy Real-Time Machine Learning

Learn how to simplify machine learning integration using Google’s Mediapipe Tasks API. Discover its key features, supported tasks, and step-by-step guidance for building real-time ML applications

Jun 14, 2025
Read
Top

Boosting AI Performance: Accelerated Inference Using Optimum and Transformers Pipelines

How accelerated inference using Optimum and Transformers pipelines can significantly improve model speed and efficiency across AI tasks. Learn how to streamline deployment with real-world gains

Jul 02, 2025
Read
Top

Dealing With Limited Datasets in Machine Learning: A Complete Guide

Struggling with a small dataset? Learn practical strategies like data augmentation, transfer learning, and model selection to build effective machine learning models even with limited data

Jun 20, 2025
Read
Top

The Role of the Expert Acceleration Program in Advancing Sempre Health ML Roadmap

How Sempre Health is accelerating its ML roadmap with the help of the Expert Acceleration Program, improving model deployment, patient outcomes, and internal efficiency

Jul 01, 2025
Read
Top

A Step-by-Step Guide to Training Language Models with Megatron-LM

How to train large-scale language models using Megatron-LM with step-by-step guidance on setup, data preparation, and distributed training. Ideal for developers and researchers working on scalable NLP systems

Jun 30, 2025
Read
Top

Why BigQuery Is the Backbone of Modern Data Analytics

Discover how Google BigQuery revolutionizes data analytics with its serverless architecture, fast performance, and versatile features

Jun 19, 2025
Read
Top

What Summer Means at Hugging Face: A Season of Open-Source AI Growth

How Summer at Hugging Face brings new contributors, open-source collaboration, and creative model development to life while energizing the AI community worldwide

Jul 03, 2025
Read
Top

How Knowledge Graphs Make Data Smarter

Discover how knowledge graphs work, why companies like Google and Amazon use them, and how they turn raw data into connected, intelligent systems that power search, recommendations, and discovery

Jun 18, 2025
Read
Top

Avoid These PyTorch Pitfalls to Improve Your Workflow

Are you running into frustrating bugs with PyTorch? Discover the common mistakes developers make and learn how to avoid them for smoother machine learning projects

Jun 16, 2025
Read