SNS Notification for File Uploads and Deletions in S3 Bucket

Nivas DevSecOps
4 min readSep 16, 2024

--

Introduction:

In this blog, we are going to learn how we can receive an SNS email notification whenever any object is uploaded or removed from AWS S3 bucket.

Amazon S3 is a highly specialized file storage system. Similar to file folders, Amazon S3 buckets allow you to store, retrieve, backup, and access things.

There are four different categories of objects that cause events. Put, Post, Copy, Multipart Upload, Remove, Replicate, and Restore are some of their verbs. As a result, anytime any of the events happen in our S3 bucket, a notification is published to a topic, where subscribers can access the messages.

Amazon Simple Notification Service (Amazon SNS) organizes and controls the transmission of messages to clients or endpoints that have subscribed to them.

You can add subscribers to an SNS subject and then publish messages to all of those subscribers.

Architecture:

Steps:

a. Creating S3 bucket:

i. Navigate to S3 Console.

ii. Click on Create bucket.

iii. Enter Bucket name, choose on AWS Region where you want to create bucket and click on Create.

b. Create SNS Notification:

i. Navigate SNS Console.

ii. Click on Create topic.

iii. Choose topic type as Standard, Enter topic Name and Description.

iv. In access policy, Choose Basic Method and Specify Publishers and Subscribers as “Everyone” and click on Create topic.

c. Subscribe to SNS Topic:

i. Once SNS topic created, in Subscription tab, Click on Create Subscription.

ii. Select Protocol as Email and Enter Email address in Endpoint and Click on Create.

iii. After subscription is created, you can see status as “Pending Acceptance”.

iv. You will receive Mail to Email address provided in the previous step to confirm Subscription.

v. Once you confirm, Subscription status is confirmed. Now Subscribed Email address will start receiving mails.

d. Create S3 Event:

i. Navigate to S3 Console.

ii. Choose the bucket for which you wish to configure the notifications.

iii. In Properties tab, click on create event notification.

iv. Enter Event name, choose Event types as Object creation and Object removal, Destination as SNS topic and Specify SNS topic by choosing SNS topic from the list or by providing SNS topic ARN and Click on Save changes.

e. Test:

An email will be sent to your subscribed email address if you try to upload or delete any files from that S3 bucket

Upload:

Hope it helps..!

Thank you for reading so far! Before you go:

--

--

Nivas DevSecOps
Nivas DevSecOps

Written by Nivas DevSecOps

Cloud | DevSecOps| AWS ⭐Passionate Cloud and DevOps . 🎯 Like to stay up-to-date with the latest trends and insights.

Responses (1)