Automating S3 Event Notifications Using Lambda and SNS

Title: How I Automated S3 Event Notifications Using AWS Lambda and SNS
Overview
For this week blogs, I will talk about how I implemented a real-world automation workflow using Amazon S3, AWS Lambda, and Amazon SNS. My goal? To automatically send myself an email notification every time a new file was uploaded to a specific S3 bucket.
This kind of automation is not only useful for personal projects but also a common pattern in enterprise workflows for building responsive, event-driven systems.
π§ What I Did
Hereβs a breakdown of the steps I followed:
1. Created an S3 Bucket
I started by creating a new Amazon S3 bucket where files would be uploaded. This bucket serves as the trigger source for the event notifications.
2. Wrote a Lambda Function to Process Events
Next, I created a Lambda function using Node.js (you can use Python or other supported runtimes). The function is designed to receive S3 event data and publish a message to SNS.
javascriptCopyEditconst AWS = require('aws-sdk');
const sns = new AWS.SNS();
exports.handler = async (event) => {
const bucketName = event.Records[0].s3.bucket.name;
const objectKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
const message = `New file uploaded:\nBucket: ${bucketName}\nFile: ${objectKey}`;
const params = {
Message: message,
Subject: "S3 Upload Notification",
TopicArn: process.env.SNS_TOPIC_ARN,
};
await sns.publish(params).promise();
return {
statusCode: 200,
body: JSON.stringify('Notification sent.'),
};
};
I also set the SNS_TOPIC_ARN as an environment variable in the Lambda console.
3. Set Up Amazon SNS for Email Notifications
I created an SNS topic and subscribed my email address to it. Once confirmed, this topic could now receive messages from Lambda and forward them via email.
4. Integrated Everything
The final step was connecting the pieces:
S3 bucket β Lambda trigger: I enabled event notifications in the S3 bucket settings to trigger the Lambda function on
PUTevents (file uploads).Lambda β SNS: The Lambda function sends a message to SNS when triggered.
SNS β Email: SNS forwards the message as an email notification to my subscribed address.
βοΈ Tools Used
Amazon S3 β For storing uploaded files.
AWS Lambda β To process S3 events and publish messages.
Amazon SNS β To send email notifications.
IAM Roles β For securely granting permissions between services.
π Why This Matters
In modern cloud-native applications, automated notifications and serverless event-driven pipelines reduce manual intervention and boost operational responsiveness. Whether you're monitoring logs, triggering batch jobs, or alerting on file uploads, this architecture pattern is powerful and scalable.
π Key Learnings
IAM roles and permissions are crucial. Lambda needs permissions to read from S3 and publish to SNS. Setting up the correct execution role was key to getting this workflow running.
CloudWatch Logs made debugging Lambda functions straightforward. I was able to trace the event structure and confirm that the message was being sent as expected.
SNS supports multiple subscribers β not just email, but also SMS, HTTP endpoints, and AWS Lambda functions. This makes it a flexible tool for multi-channel alerting.

