AWS Builder Center

My First AWS Lambda Function: A Python Walkthrough, as a Student

My first AWS Lambda function in Python, as a student: create it in the console, test it with a JSON event, read the logs in CloudWatch, and clean up. No server, no framework.

My First AWS Lambda Function: A Python Walkthrough, as a Student

Introduction

I am a B.Tech software engineering student learning AWS, and after hosting a static website on Amazon S3, the next thing I wanted to understand was serverless: code that runs without me managing a server at all. AWS Lambda is the simplest place to start.
In this article, I will walk through exactly how I created my first Lambda function in Python: writing a small function, testing it in the console, reading the logs, and cleaning up afterwards. If you can write a few lines of Python, you can follow this guide. No framework, no deployment tool, and no server to look after.

What you will build

A Lambda function that:
  • Takes a JSON event as input
  • Returns a friendly greeting, plus the name it was given
  • Logs what it did, so you can see the run in CloudWatch
This is a good first step towards real serverless work — an API behind API Gateway, a function triggered by an S3 upload, or a scheduled task. It is not a production setup: there is no error handling for bad input beyond the basics, no custom domain, and no CI/CD. Those come later.

Prerequisites

  • An AWS account with access to Lambda (the AWS Free Tier covers the usage in this guide)
  • A browser — everything here is done in the AWS Management Console, no CLI needed
  • Basic Python: functions, dictionaries, and f-strings

Step 1: Create the function

In the console, go to Lambda, choose Create function, and pick Author from scratch. Fill in:
  • Function name:  hello-student  (use your own name if you like)
  • Runtime: Python 3.13
  • Architecture: x86_64
Leave the execution role as the default: Lambda creates a role with basic permissions to write logs to CloudWatch. That is all this function needs.
Choose Create function. Lambda opens the code editor with a starter function already in place.

Step 2: Write the code

Replace the starter code in  lambda_function.py  with this:
def lambda_handler(event, context):
name = event.get("name", "World")
message = f"Hello, {name}! Your first Lambda function is running."
print(f"Greeted: {name}")
return {
"statusCode": 200,
"body": message
}
Two things to notice if this is your first Lambda function:
  1.  lambda_handler(event, context)  is the entry point. Lambda calls it every time the function runs.  event  is the input — here, a JSON object.  context  carries information about the run itself, such as how much time is left.
  1.  print()  is not just for debugging here. Lambda sends everything you print to CloudWatch Logs, which is how you see what happened after a run.
Choose Deploy to save this version of the code. Until you deploy, Lambda keeps running the previous saved version — this catches almost every beginner out at least once, and it caught me.

Step 3: Test it in the console

Choose Test. Lambda asks for a test event — a sample JSON input. Create a new event called  TestHello  with this body:
{
"name": "Awej"
}
Use your own name. Save the event, then choose Test again to run it.
You should see a green "Execution result: succeeded" box, with something like:
{
"statusCode": 200,
"body": "Hello, Awej! Your first Lambda function is running."
}
Below that, the log output shows  Greeted: Awej , plus the billed duration and memory used. For a function this small, the duration is a few tens of milliseconds and the memory used is well under the 128 MB default.
Try it again with a different name, or with an empty event  {}  — the  .get("name", "World")  fallback means it greets "World" instead of crashing. Small defaults like that are worth building in from the start.

Step 4: Read the logs in CloudWatch

The test output shows the most recent logs, but for a function triggered by something else — an S3 upload, an API call — you need CloudWatch.
In the Lambda console, open the Monitor tab, then choose View CloudWatch logs. Each run creates a log stream, and each stream holds the  print()  lines from that run, with timestamps.
If you ever see an error instead of a greeting, this is the first place to look. The most common beginner errors are a typo in the function name in the handler setting ( lambda_function.lambda_handler  must match the file name and the function name), and forgetting to Deploy after editing the code.

Step 5: What it costs, and how to clean up

For a function this small, the AWS Free Tier gives you 1 million free requests and 400,000 GB-seconds of compute every month, so experimenting like this costs nothing in practice. Always check the billing dashboard in your own account, though — free-tier limits can change, and a function triggered in a loop by mistake is the classic way a small experiment stops being free.
When you are done, delete the function so it does not sit there forgotten: in the Lambda console, open the function, choose Actions, then Delete. That also removes its log group over time. Deleting the function does not delete the execution role Lambda created for it; you can remove that from IAM if you want a fully clean slate, but leaving one unused role behind is harmless.

What I learned

  • Lambda is just a function with a trigger. The console test event is the simplest trigger there is.
  •  event  is your input,  context  is your run, and  print()  is your window into both.
  • Deploy is a separate step from editing. If your change seems to have no effect, check that first.
  • A default value on input (here, "World") turns a crash into a polite answer.

What I will try next

My next step is to connect this function to something real: an API Gateway endpoint so I can call it from a browser, and then a trigger on my S3 static website bucket — the site from my last article — so an upload can kick off a function automatically. If you have done either of those as a student, I would love to hear what tripped you up in the comments.
Thank you for reading — and if this helped you run your first function, let me know what you built with it.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article