{"id":46246,"date":"2017-02-22T16:25:52","date_gmt":"2017-02-22T10:55:52","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=46246"},"modified":"2017-02-22T16:25:52","modified_gmt":"2017-02-22T10:55:52","slug":"configuring-sns-notifications-for-s3-put-object-event-operation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/configuring-sns-notifications-for-s3-put-object-event-operation\/","title":{"rendered":"Configuring SNS Notifications For S3 Put Object Event Operation"},"content":{"rendered":"<p>S3 is an amazing service provided by <a href=\"http:\/\/www.tothenew.com\/devops-aws\">AWS<\/a> for unlimited data storage. <a title=\"Amazon S3\" href=\"http:\/\/www.tothenew.com\/blog\/?s=amazon+S3\">S3<\/a> 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.<br \/>\n<strong><br \/>\nUse case:<\/strong>\u00a0I&#8217;ve come up with a use case where an application &#8220;A&#8221; publishes some XML reports to a particular folder on S3 bucket. These reports are consumed by another application &#8220;B&#8221; which converts these XML reports into human readable HTML reports.<\/p>\n<p>I&#8217;ve used SNS notifications triggered by S3 bucket whenever an object is put on a\u00a0particular folder in S3.<\/p>\n<p>You can follow the below steps to achieve the same:<\/p>\n<p><strong>Step 1: Create an Amazon SNS topic for the Email Notifications:\u00a0<\/strong>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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46300\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-sns-1-edit.png\" alt=\"s3-sns-1-edit\" width=\"1025\" height=\"401\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-sns-1-edit.png 1025w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-sns-1-edit-300x117.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-sns-1-edit-1024x400.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-sns-1-edit-624x244.png 624w\" sizes=\"(max-width: 1025px) 100vw, 1025px\" \/><\/p>\n<p><strong>Step 2: Allow S3 bucket to publish notification to SNS topic by replacing SNS topic&#8217;s policy by the below policy:<\/strong><\/p>\n<p>[js]<\/p>\n<p>{<br \/>\n&quot;Version&quot;: &quot;2008-10-17&quot;,<br \/>\n&quot;Id&quot;: &quot;s3-sns&quot;,<br \/>\n&quot;Statement&quot;: [<br \/>\n{<br \/>\n&quot;Sid&quot;: &quot;s3-sns-sid&quot;,<br \/>\n&quot;Effect&quot;: &quot;Allow&quot;,<br \/>\n&quot;Principal&quot;: {<br \/>\n&quot;AWS&quot;: &quot;*&quot;<br \/>\n},<br \/>\n&quot;Action&quot;: &quot;SNS:Publish&quot;,<br \/>\n&quot;Resource&quot;: &quot;&lt;SNS Topic ARN&gt;&quot;,<br \/>\n&quot;Condition&quot;: {<br \/>\n&quot;ArnLike&quot;: {<br \/>\n&quot;aws:SourceArn&quot;: &quot;arn:aws:s3:*:*:&lt;S3 Bucket Name&gt;&quot;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n]<br \/>\n}<br \/>\n[\/js]<\/p>\n<p><strong><strong>Step 3: Configure S3 bucket Notification Configurations:\u00a0<\/strong><\/strong>For demo purposes, I am showing the configuration where all the objects will be pushed to one S3 folder (named &#8220;test&#8221;) in the bucket. Below is the description of the configuration:<\/p>\n<p><strong>Name:<\/strong> The descriptive name of the configuration\u00a0<strong><br \/>\nEvents:\u00a0<\/strong>The name of the S3 object events on which the notification needs to be triggered<br \/>\n<strong>Prefix:\u00a0<\/strong>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\u00a0particular folder in which the objects will be pushed.<br \/>\n<strong>Suffix:\u00a0<\/strong>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.<br \/>\n<strong>Send To:\u00a0<\/strong>The way of sending notification (SNS Topic or SQS Queue)<br \/>\n<strong>SNS Topic:\u00a0<\/strong>The topic ARN of the SNS topic on which the notifications will be sent.<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46250\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-2.png\" alt=\"s3-2\" width=\"611\" height=\"442\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-2.png 611w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-2-300x217.png 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/>\u00a0<\/strong><\/p>\n<p><strong>\u00a0<strong><strong>Step 4:\u00a0Save and test the configurations:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46301\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-email-edited.png\" alt=\"s3-email-edited\" width=\"689\" height=\"143\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-email-edited.png 689w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-email-edited-300x62.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/s3-email-edited-624x129.png 624w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/><br \/>\n<\/strong><\/strong><\/strong><\/p>\n<p>By following the above steps, you can make use of S3 event notifications for asynchronous tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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:\u00a0I&#8217;ve come up [&hellip;]<\/p>\n","protected":false},"author":170,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":36},"categories":[1174,1],"tags":[1276,4443],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/46246"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=46246"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/46246\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=46246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=46246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=46246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}