{"id":2810,"date":"2018-07-11T21:21:35","date_gmt":"2018-07-11T21:21:35","guid":{"rendered":"http:\/\/blog.paranoidprofessor.com\/?p=2810"},"modified":"2018-07-29T08:28:46","modified_gmt":"2018-07-29T08:28:46","slug":"aws-s3-and-simple-notifications","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2018\/07\/11\/aws-s3-and-simple-notifications\/","title":{"rendered":"AWS &#8211; S3 and Simple Notifications"},"content":{"rendered":"<p>Individual Amazon web services are actually quite amazing all on their own but they are really neat when you start to use them together.<\/p>\n<p>There probably isn&#8217;t anyone who in their life hasn&#8217;t had a sdcard or hard disk fill up who just needed a small bit of extra space to complete their action.\u00a0 Of course in that situation in the real world you have to stop what you are doing and free up (ie delete something) so you can continue.<\/p>\n<p>Amazon S3 doesn&#8217;t have that problem.\u00a0 If you have the budget, you can keep adding data to it until you are satisfied you are finished.\u00a0 Sure you have to keep on eye on the costs but that is a completely separate issue.<\/p>\n<p>However, it isn&#8217;t any one service that makes AWS so cool as much as how they all seem work together.\u00a0 One such example of that is the ability to send notifications based on some event that has occurred.\u00a0 This might be an event you setup to monitor your costs or it might be used as a trigger to an application.<\/p>\n<p>In my case, I am going to demonstrate an email notification going out if a file ends up in a S3 bucket.\u00a0 If you were some sort of picture site, this might instead be triggering a lambda function to create thumbnails or perhaps this information might be put into a queue for some other processing (or both).<\/p>\n<p>In my previous article,\u00a0AWS &#8211; Simple Notification Service,\u00a0I discussed everything that needs to be done in order to setup a Simple Notification Service topic but in this blog entry I will actually use put the AWS SNS to use.<\/p>\n<p>In addition to sending out messages, I will also add replication to a s3 bucket.\u00a0 This will provide a cool way to put data into one bucket and watch it being replicated to the second bucket.\u00a0 This replication is pretty much as the name says.\u00a0 If you add data to the source bucket, it will be added to the destination bucket but if you delete it from the source bucket it will also be deleted from the destination bucket.<\/p>\n<h2>Replication<\/h2>\n<p>The replication is actually quite simple. The setup is essentially from where do you want to copy what, and where should it be placed.\u00a0 Replication setup is available from the management tab on the bucket.<\/p>\n<div id=\"attachment_2816\" style=\"width: 716px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2816\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2816\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-1source.png\" alt=\"\" width=\"706\" height=\"707\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-1source.png 706w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-1source-150x150.png 150w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-1source-300x300.png 300w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><p id=\"caption-attachment-2816\" class=\"wp-caption-text\">source<\/p><\/div>\n<p>It is also possible, actually recommended that you check the checkbox to encrypt the objects that are replicated.<\/p>\n<div id=\"attachment_2817\" style=\"width: 717px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2817\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2817\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-2dest.png\" alt=\"\" width=\"707\" height=\"708\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-2dest.png 707w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-2dest-150x150.png 150w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-2dest-300x300.png 300w\" sizes=\"(max-width: 707px) 100vw, 707px\" \/><p id=\"caption-attachment-2817\" class=\"wp-caption-text\">Destination<\/p><\/div>\n<p>The replicated box must be in another region.\u00a0 It is also possible to change the storage class in the destination.\u00a0 By selecting a class with a different type it may be possible to reduce the cost of the storage in this additional location.<\/p>\n<div id=\"attachment_2818\" style=\"width: 715px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2818\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2818\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-3permission.png\" alt=\"\" width=\"705\" height=\"706\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-3permission.png 705w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-3permission-150x150.png 150w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-3permission-300x300.png 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><p id=\"caption-attachment-2818\" class=\"wp-caption-text\">Permissions<\/p><\/div>\n<p>I did not create this IAM rule, nor name myself &#8211; I had it created for me.\u00a0 This is necessary in order to allow the proper read and writing for these two S3 buckets.<\/p>\n<div id=\"attachment_2819\" style=\"width: 714px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2819\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2819\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-4review.png\" alt=\"\" width=\"704\" height=\"707\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-4review.png 704w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-4review-150x150.png 150w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3rep-4review-300x300.png 300w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><p id=\"caption-attachment-2819\" class=\"wp-caption-text\">Review<\/p><\/div>\n<p>Once the replication setup has been saved then new data that is saved or deleted from the source bucket will be replicated a short while later in the destination bucket.<\/p>\n<h2>Notifications<\/h2>\n<p>The actual notifications on the S3 bucket are trivial to setup.\u00a0 Simply go to the properties of the bucket and setup an &#8220;event&#8221;.<\/p>\n<div id=\"attachment_2826\" style=\"width: 556px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-2826\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2826\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event.png\" alt=\"\" width=\"546\" height=\"885\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event.png 546w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event-185x300.png 185w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><p id=\"caption-attachment-2826\" class=\"wp-caption-text\">Delete event setup<\/p><\/div>\n<p>It is possible to be notified depending on which type of action occurred, ranging from simple create or even just simple HTTP commands.<\/p>\n<p>However, it might not be quite that simple as it appears on first look.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2827 aligncenter\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event-fail.png\" alt=\"\" width=\"474\" height=\"128\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event-fail.png 474w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-delete-event-fail-300x81.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/p>\n<p>You might get an error if the permissions are not properly setup in the simple notification service.<\/p>\n<div id=\"attachment_2828\" style=\"width: 911px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2828\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2828\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-before.png\" alt=\"\" width=\"901\" height=\"701\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-before.png 901w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-before-300x233.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-before-768x598.png 768w\" sizes=\"(max-width: 901px) 100vw, 901px\" \/><p id=\"caption-attachment-2828\" class=\"wp-caption-text\">Original notification setup<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_2829\" style=\"width: 914px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-2829\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2829\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-after.png\" alt=\"\" width=\"904\" height=\"640\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-after.png 904w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-after-300x212.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-01-s3sns-delete-policy-after-768x544.png 768w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><p id=\"caption-attachment-2829\" class=\"wp-caption-text\">Proper &#8211; notification setup<\/p><\/div>\n<p>Once you setup the proper permissions in the simple notification setup you can then create and save other rules as long as they do not overlap in functionality (ie two different types of create)<\/p>\n<div id=\"attachment_2830\" style=\"width: 558px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-2830\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2830\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-create-event.png\" alt=\"\" width=\"548\" height=\"885\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-create-event.png 548w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2018\/01\/aws-00-s3sns-create-event-186x300.png 186w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><p id=\"caption-attachment-2830\" class=\"wp-caption-text\">create event setup<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Individual Amazon web services are actually quite amazing all on their own but they are really neat when you start to use them together. There probably isn&#8217;t anyone who in their life hasn&#8217;t had a sdcard or hard disk fill &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2018\/07\/11\/aws-s3-and-simple-notifications\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[95,90,85],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2810"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=2810"}],"version-history":[{"count":8,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2810\/revisions"}],"predecessor-version":[{"id":2832,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2810\/revisions\/2832"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=2810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=2810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=2810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}