Create S3 Bucket Event Notification using Amazon SNS (Simple Notification Service)

Create S3 Bucket Event Notification using Amazon SNS (Simple Notification Service)

Jineshkumar Patel's photo
Jineshkumar Patel
·Jun 27, 2022·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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.

  1. 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 myS3SNSTopic 1.png

  2. Creation 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. 2.png 3.png 4.png 5.png

  3. Creation of Amazon S3 Bucket : Create an S3 bucket with a globally unique name. Mine is "s3snsenabledbucket" 6.0.png

  4. Configuration of SNS Topic Access Policy : Configured Amazon SNS Topic Access Policy that allows S3 Service from our AWS Account to publish Event Notification. 7.png

     "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"
                 }
             }
         }
     ]
    }
    
  5. 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. screely-1656219515372.png

  6. 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, screely-1656219759691.png
    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.
    screely-1656219976741.png 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

 
Share this