AWS Builder Center
From File Upload to Automation: Building an S3 + Lambda Project ☁️

From File Upload to Automation: Building an S3 + Lambda Project ☁️

Discover how to connect Amazon S3 with AWS Lambda and automatically trigger a Python function whenever a file is uploaded. Follow this beginner-friendly hands-on project to explore event-driven architecture, serverless computing, IAM permissions, and CloudWatch monitoring.

Computer Engineering Student | AWS | AI Agents | Cloud Computing | Cybersecurity
What if uploading a file could automatically trigger an action in the cloud?
That's one of the interesting things we can build with AWS. In this beginner-friendly project, we'll connect Amazon S3 with AWS Lambda so that uploading a file to an S3 bucket automatically triggers a Python function.
No server management. No complicated application. Just a small project that introduces event-driven computing!

🌷 What are we going to build?

Imagine a student application where users upload assignment files.
Whenever a new file arrives in an S3 bucket, AWS Lambda automatically runs a function and records information about the uploaded object.
Our workflow:
User → Amazon S3 → S3 Event Notification → AWS Lambda → Amazon CloudWatch Logs
We'll use:
  • Amazon S3: Stores uploaded files.
  • AWS Lambda: Runs our Python code when triggered.
  • Amazon CloudWatch: Helps us inspect the function's execution logs.

Step 1: Create an S3 bucket

  1. Open the AWS Management Console.
  1. Search for Amazon S3.
  1. Select Create bucket.
  1. Choose a globally unique bucket name.
  1. Select an AWS Region.
  1. Keep Block Public Access enabled.
  1. Create the bucket.
For this project, we'll use a private bucket. We don't need to make uploaded files public.

Step 2: Create a Lambda function

  1. Open AWS Lambda.
  1. Select Create function.
  1. Choose Author from scratch.
  1. Give it a name, such as  S3UploadLogger .
  1. Select Python as the runtime.
  1. Create the function.
Lambda will provide an execution role. This role controls what the function is allowed to do.
For this basic example, we'll only log the uploaded object's details. We don't need to grant the function permission to read or delete files.

Step 3: Add a simple Python function

Replace the sample code in the Lambda editor with:
def lambda_handler(event, context):
for record in event.get("Records", []):
bucket = record["s3"]["bucket"]["name"]
key = record["s3"]["object"]["key"]

print("New file uploaded!")
print("Bucket:", bucket)
print("File:", key)

return {
"statusCode": 200,
"message": "Upload event processed"
}
This function reads the S3 event information and prints the bucket name and uploaded object key.
Notice that the function doesn't need to continuously check the bucket. S3 sends an event when a configured upload event occurs.

Step 4: Connect S3 to Lambda

Now let's connect both services.
  1. Open your S3 bucket.
  1. Go to Properties.
  1. Find Event notifications.
  1. Select Create event notification.
  1. Give it a name, such as  NewFileUploaded .
  1. Select the object creation event types you want to handle.
  1. Under the destination, choose Lambda function.
  1. Select your  S3UploadLogger  function.
  1. Save the notification.
AWS can configure the required permission for S3 to invoke the Lambda function when you create this integration through the console.

Step 5: Test the project

Let's see the workflow in action!
  1. Open your S3 bucket.
  1. Select Upload.
  1. Upload a small test file.
  1. Open your Lambda function.
  1. Go to the Monitor section.
  1. Open the CloudWatch logs.
If everything is configured correctly, you should find log messages showing the bucket name and uploaded file key.
Congratulations! Your first event-driven AWS workflow is working. 🎉

Step 6: Understand a few important things

A working demo is a great beginning, but real applications need additional care.
1. Avoid recursive triggers
If a Lambda function writes new files into the same bucket that triggers it, those uploads may invoke the function again. Use a separate output bucket or configure event filters carefully.
2. Remember that events can be delivered more than once
S3 event notifications are designed for at-least-once delivery. Your application should be prepared for duplicate events. Consider idempotency when processing uploads.
3. Follow least privilege
Give the Lambda execution role only the permissions needed for its task. Don't grant broad S3 access unnecessarily.
4. Monitor failures
Use CloudWatch logs and metrics to investigate errors and understand how your function behaves.

What did we learn?

This small project introduces some important AWS concepts:
  • Object storage with Amazon S3.
  • Event-driven architecture.
  • Serverless computing with Lambda.
  • Permissions through IAM roles.
  • Monitoring through CloudWatch.

🌱 What's next?

You can extend this project in several ways:
  • Generate thumbnails when images are uploaded.
  • Validate uploaded file types.
  • Store upload details in DynamoDB.
  • Send notifications when a file arrives.
  • Build a document-processing workflow.
Before experimenting, review current AWS pricing and applicable Free Tier eligibility. Services and usage can incur charges. Use test files, and clean up resources when you're finished.

💬 Let's discuss!

Imagine you're building a college assignment submission system.
What would you add after a student uploads a file?
  1. Automatically validate the file.
  1. Generate a notification for the teacher.
  1. Save upload details in DynamoDB.
  1. Scan the file before making it available.
I'd love to hear what other AWS builders would build next!
Happy building! ☁️💗
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