S3 is an amazing service provided by AWS for unlimited data storage. S3 provides various types of event notifications whenever an operation has been done on the S3 object(s). One can notify about the S3 object operations to other services by means of SQS, SNS and by triggering AWS Lambda functions.
Use case: I’ve come up with a use case where an application “A” publishes some XML reports to a particular folder on S3 bucket. These reports are consumed by another application “B” which converts these XML reports into human readable HTML reports.
I’ve used SNS notifications triggered by S3 bucket whenever an object is put on a particular folder in S3.
You can follow the below steps to achieve the same:
Step 1: Create an Amazon SNS topic for the Email Notifications: First of all, create an Amazon SNS topic which publishes notifications to email. After creating the SNS topic, create a subscription for the target email ID.
Step 2: Allow S3 bucket to publish notification to SNS topic by replacing SNS topic’s policy by the below policy:
"Resource": "<SNS Topic ARN>",
"aws:SourceArn": "arn:aws:s3:*:*:<S3 Bucket Name>"
Step 3: Configure S3 bucket Notification Configurations: For demo purposes, I am showing the configuration where all the objects will be pushed to one S3 folder (named “test”) in the bucket. Below is the description of the configuration:
Name: The descriptive name of the configuration
Events: The name of the S3 object events on which the notification needs to be triggered
Prefix: The prefix is the starting name of the objects which are put on the S3 bucket. You can also specify a unique name of the particular folder in which the objects will be pushed.
Suffix: The suffix is the ending name of the objects on which you want to trigger the notifications when they are pushed to S3. For eg., I want to trigger notifications for all the .png objects pushed to the S3 bucket.
Send To: The way of sending notification (SNS Topic or SQS Queue)
SNS Topic: The topic ARN of the SNS topic on which the notifications will be sent.
Step 4: Save and test the configurations:
By following the above steps, you can make use of S3 event notifications for asynchronous tasks.