DEV Community

Cover image for SNS notification for S3 static website
jicoing
jicoing

Posted on • Edited on

SNS notification for S3 static website

About

With S3 event notification we can configure our S3 bucket to easily send out event notification mail, on every visit to our static website. We need to setup our cloudfront distribution for standard logging. Once the log data is PUT into our S3 bucket, an notification is sent out via SNS topic to the subscription of our choice.

Cloudfront

First we need to setup our Cloudfront distribution for access logging.

  • Go the the distribution. Alt Text
  • Edit settings Alt Text
  • Enable Standard logging Mention the bucket name and optional prefix. Alt Text
  • Once standard logging is setup we can see the log data periodically being PUT in the specified S3 bucket. Alt Text

SNS

Now we can configure our SNS topic to send nofication mail on every log data PUT to our S3 bucket.

  • Create a SNS topic The SNS topic must be in the same region as the bucket. Alt Text Mention name and display name and create Alt Text Once the topic is created, add a subscription with protocol email and destination mail ID. Alt Text You will be receiving a confirmation mail, go ahead and confirm it. Once it is confirmed it should look like this. Alt Text

Configure SNS access policy

Now we have to configure the SNS topic access policy to access the S3 bucket.

  • Edit the SNS topic Alt Text
  • Replace the access policy JSON with the below policy after replacing SNS-topic-ARN, bucket-name, bucket-owner-account-id with the required ones. Official guide.

Alt Text

S3

Go to properties tabs from inside your destination S3 bucket and create event notification.
Alt Text
Give an event name, and mention the optional prefix where Cloudfront log data is stored.
Alt Text
Check event type as PUT
Alt Text
Check SNS as your destination, your topic should show up in the drop down automatically, if the topic region matches the bucket region and the SNS policy is configured correctly.
Alt Text
Click finish.
We are now configured to receive notifications!

Sample notification mail showing event time and log file of type gz
Alt Text

Top comments (0)