Create S3 Bucket Event Notification using Amazon SNS (Simple Notification Service)
Table of contents
Real-World Scenario: A company XYZ is deploying a new web application that helps customers to upload files to S3 Bucket. As a part of the infrastructure, the Administrator needs to be notified via Email whenever an object is put into their S3 bucket.
This Blog is to set up the AWS architecture to perform this operation.
Instructions to complete this challenge.
Creation of SNS topic: "An Amazon SNS topic is a logical access point that acts as a communication channel that provides message delivery from publishers to subscribers (also known as pub-sub model)".
Created a Standard Amazon SNS topic named myS3SNSTopicCreation of Subscription: "To receive messages published to a topic, you must subscribe an endpoint to the topic. When you subscribe an endpoint to a topic, the endpoint begins to receive messages published to the associated topic".
Created and Added an Email subscription to that topic and verified it.Creation of Amazon S3 Bucket : Create an S3 bucket with a globally unique name. Mine is "s3snsenabledbucket"
Configuration of SNS Topic Access Policy : Configured Amazon SNS Topic Access Policy that allows S3 Service from our AWS Account to publish Event Notification.
"Version": "2012-10-17", "Id": "example-ID", "Statement": [ { "Sid": "Example SNS topic policy", "Effect": "Allow", "Principal": { "Service": "s3.amazonaws.com" }, "Action": [ "SNS:Publish" ], "Resource": "SNS-topic-ARN", "Condition": { "ArnLike": { "aws:SourceArn": "arn:aws:s3:*:*:bucket-name" }, "StringEquals": { "aws:SourceAccount": "bucket-owner-account-id" } } } ] }
Creation of Event Notification for S3 Bucket: Created S3 Bucket's Notification Event S3ObjectUpload EventNotification.
Select S3 Event type as Put.
Select SNS Topic as event Destination.Test the Configuration by uploading any sample PNG image file to S3 Bucket and see if I am notified on my defined Email.
Test Image uploaded,
Wooaahlla !! Confirm Email notification – As soon as the object is uploaded, an S3 "Put" event is triggered, and it publishes the messages to the SNS topic we have created "myS3SNSTopic" and the event has an "Email" Subscriber as my Gmail address.
Here I received the email from "myS3SNSTopic" with the Subject line "Amazon S3 Notification" and it was Lightning fast with no delay at all.
Walkthrough: Configuring a bucket for notifications (SNS topic or SQS queue)
This concludes successfully configuring an s3 bucket event to SNS Topic and is able to get event notification through "Email" subscribers.
This will be helpful to monitor and get updated on any expected or unexpected Bucket Events like Put or Delete.
Hope this is helpful to understand and follow along.
Feel free to like and follow for more such content.
Thanks
Jineshkumar Patel
Subscribe to my newsletter
Read articles from Jineshkumar Patel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Jineshkumar Patel
Jineshkumar Patel
Cloud Enthusiast working as Cloud Infrastructure Consultant. My Hobby is to build and destroy Cloud Projects for Blogs. Love to share my learning journey about DevOps, AWS and Azure. Subscribe and Follow up with "CloudCubes".Thank you and Happy Learning !!