โ๏ธ Day 30: AWS S3 & Lambda โ Object Storage + Serverless Automation

Table of contents
- ๐ง Theory: What Is Amazon S3?
- ๐ง Theory: What Is AWS Lambda?
- ๐ง AWS S3 Setup โ Step-by-Step (Static Website Hosting)
- โจ Project Highlight: ๐ Personal Portfolio Hosted on S3
- ๐ AWS Lambda Triggered by S3 Upload
- ๐ช Setup: Lambda + S3 Trigger (Python Example)
- ๐ฆ Use Case Examples
- ๐งช Sample CLI Commands
- ๐ก๏ธ Best Practices
- ๐ Summary
- ๐ฎ Whatโs Next?

Todayโs deep dive covers two fundamental AWS services:
Amazon S3: Scalable object storage for static files, backups, and web hosting.
AWS Lambda: Serverless compute service that executes code on-demand without provisioning servers.
We also showcase a real-world project where a personal portfolio website is hosted on S3, and explore how Lambda functions can be triggered by S3 events, e.g., for automation on file upload.
๐ง Theory: What Is Amazon S3?
Amazon Simple Storage Service (S3) is:
A durable, highly scalable object storage system.
Used to store files like images, videos, HTML, JSON, CSV, backups, etc.
Common for:
Hosting static websites
Media content delivery
Data lake storage
Backup and restore
Triggering serverless actions
Each object is stored in a bucket and identified by a key (file path).
๐ง Theory: What Is AWS Lambda?
AWS Lambda is a serverless compute service that:
Runs your code in response to triggers/events
Supports languages like Python, Node.js, Java, Go, etc.
No server management
You only pay for execution time
Common triggers:
S3 (file upload)
API Gateway
DynamoDB Streams
CloudWatch Events
SNS/SQS
๐ง AWS S3 Setup โ Step-by-Step (Static Website Hosting)
โ Step 1: Create S3 Bucket
aws s3 mb s3://my-portfolio-website
โ Step 2: Enable Static Website Hosting
From AWS Console โ S3 โ Your Bucket โ Properties
Enable โStatic Website Hostingโ
Index document:
index.html
Error document:
error.html
(optional)
โ Step 3: Set Bucket Policy for Public Read
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-portfolio-website/*"
}]
}
Apply this in the Permissions โ Bucket Policy section.
โ Step 4: Upload Files
aws s3 sync ./portfolio-website s3://my-portfolio-website
Your site is now live at:
http://my-portfolio-website.s3-website-<region>.amazonaws.com
โจ Project Highlight: ๐ Personal Portfolio Hosted on S3
๐ What You Built:
A responsive one-page portfolio featuring:
About
Skills
Projects
Contact section
๐งฑ Folder Structure:
portfolio-website/
โโโ index.html
โโโ style.css
โโโ images/
โโโ scripts/
๐ Hosted at:
http://your-bucket-name.s3-website-region.amazonaws.com
No server needed. No EC2. Just fast, scalable S3.
๐ AWS Lambda Triggered by S3 Upload
๐ฏ Goal:
Trigger a Lambda function when a new file is uploaded to a specific S3 bucket.
๐ช Setup: Lambda + S3 Trigger (Python Example)
โ Step 1: Create Lambda Function
From AWS Console โ Lambda โ Create function
Runtime: Python 3.9
Permissions: Create new role with basic Lambda permissions
Function code (example):
import json
def lambda_handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
print(f"File uploaded: s3://{bucket}/{key}")
return {
'statusCode': 200,
'body': json.dumps('Success')
}
โ Step 2: Add Trigger from S3
From Lambda Console:
Add trigger โ Choose S3
Choose your S3 bucket
Event type:
PUT
(Object created)Prefix (optional): e.g.,
uploads/
Suffix (optional): e.g.,
.jpg
Grant S3 permission to invoke Lambda.
๐ฆ Use Case Examples
Use Case | Trigger | Action |
Image uploads | S3 PUT | Lambda resizes images and stores thumbnails |
CSV uploads | S3 PUT | Lambda processes and stores data in DynamoDB |
Webhook-like automation | S3 PUT | Lambda sends SNS or Slack alerts |
Static logs | Lambda โ S3 | Write logs from serverless apps |
๐งช Sample CLI Commands
Create S3 Bucket
aws s3 mb s3://trigger-demo-bucket
Upload a Test File
aws s3 cp test.txt s3://trigger-demo-bucket/uploads/
Lambda will be triggered automatically.
๐ก๏ธ Best Practices
Enable versioning in S3
Use S3 Lifecycle Policies for auto-deletion
Use environment variables in Lambda
Use CloudWatch for monitoring Lambda execution
๐ Summary
Feature | Description |
S3 | Scalable object storage for static websites, media, backups |
Lambda | Serverless compute to run event-driven code |
Trigger | S3 can trigger Lambda on file uploads |
Your Project | Deployed static portfolio on S3 |
๐ฎ Whatโs Next?
๐ฎ Whatโs Next? โ Day 31 Preview
Tomorrowโs learning lineup is all about powerful AWS services that handle data, routing, and app deployment:
๐ง AWS CLI โ Automate and control your AWS services using command-line tools
๐๏ธ DynamoDB โ Explore AWS's fully managed NoSQL database
โ๏ธ Fast, scalable, and serverless
โ๏ธ Ideal for key-value and document-based workloads
๐ Route 53 โ AWS's highly available DNS service
โ๏ธ Route traffic globally
โ๏ธ Register custom domains and apply routing policies
๐ Elastic Beanstalk โ Simplified app deployment
โ๏ธ Deploy web apps without worrying about infrastructure
โ๏ธ Automatically handles provisioning, load balancing, and scaling
Stay tuned for hands-on setups, real use cases, and clear breakdowns!
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
