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.
- Edit settings
- Enable Standard logging Mention the bucket name and optional prefix.
- Once standard logging is setup we can see the log data periodically being PUT in the specified S3 bucket.
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. Mention name and display name and create Once the topic is created, add a subscription with protocol email and destination mail ID. You will be receiving a confirmation mail, go ahead and confirm it. Once it is confirmed it should look like this.
Configure SNS access policy
Now we have to configure the SNS topic access policy to access the S3 bucket.
- Edit the SNS topic
- 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.
S3
Go to properties tabs from inside your destination S3 bucket and create event notification.
Give an event name, and mention the optional prefix where Cloudfront log data is stored.
Check event type as PUT
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.
Click finish.
We are now configured to receive notifications!
Sample notification mail showing event time and log file of type gz
Top comments (0)