1 00:00:00,140 --> 00:00:02,380 ‫So now let's see how we can integrate 2 00:00:02,380 --> 00:00:05,180 ‫S3 events notifications with Lambda. 3 00:00:05,180 --> 00:00:07,230 ‫So just a reminder on S3 event notifications, 4 00:00:07,230 --> 00:00:08,807 ‫it is a way for you to get notified 5 00:00:08,807 --> 00:00:11,460 ‫whenever an object is created, removed, restored, 6 00:00:11,460 --> 00:00:13,090 ‫when there is a replication happening. 7 00:00:13,090 --> 00:00:15,390 ‫You can filter by prefix and by suffix. 8 00:00:15,390 --> 00:00:16,580 ‫And the use case is, 9 00:00:16,580 --> 00:00:19,610 ‫the classic one is to generate thumbnail images 10 00:00:19,610 --> 00:00:22,150 ‫of every image uploaded into Amazon S3. 11 00:00:22,150 --> 00:00:24,650 ‫So you have your events into Amazon S3, 12 00:00:24,650 --> 00:00:26,850 ‫and S3 can send it to three things, 13 00:00:26,850 --> 00:00:29,140 ‫to SNS and from an SNS topic, 14 00:00:29,140 --> 00:00:32,800 ‫we can do a fan out pattern to send to multiple SQ-SQ, 15 00:00:32,800 --> 00:00:34,690 ‫or we can sent it into an SQ-SQ 16 00:00:34,690 --> 00:00:38,180 ‫and have a Lambda function directly read off that SQ-SQ, 17 00:00:38,180 --> 00:00:41,700 ‫or we could have an Amazon S3 event notification, 18 00:00:41,700 --> 00:00:43,840 ‫directly invoke our Lambda function 19 00:00:43,840 --> 00:00:46,250 ‫and this is an asynchronous invocation. 20 00:00:46,250 --> 00:00:48,040 ‫And this Lambda function could do 21 00:00:48,040 --> 00:00:49,470 ‫whatever it wants with that data, 22 00:00:49,470 --> 00:00:50,810 ‫and then in case things go wrong, 23 00:00:50,810 --> 00:00:53,560 ‫we can set up a dead-letter queue, for example an SQS, 24 00:00:53,560 --> 00:00:55,180 ‫as we've seen from before. 25 00:00:55,180 --> 00:00:58,330 ‫So these S3 event notifications typically deliver events 26 00:00:58,330 --> 00:01:00,750 ‫in seconds but sometimes can take a minute or longer 27 00:01:00,750 --> 00:01:01,940 ‫and so you want to make sure 28 00:01:01,940 --> 00:01:04,370 ‫that you're not losing any event notifications, 29 00:01:04,370 --> 00:01:07,800 ‫make sure that you enable versioning on your bucket. 30 00:01:07,800 --> 00:01:09,760 ‫Otherwise, if two writes on the same object happen 31 00:01:09,760 --> 00:01:12,160 ‫at the same exact time, you may get one notification 32 00:01:12,160 --> 00:01:12,993 ‫and not two. 33 00:01:12,993 --> 00:01:14,743 ‫That's just the small print from the documentation 34 00:01:14,743 --> 00:01:17,040 ‫but one worth noting. 35 00:01:17,040 --> 00:01:17,873 ‫Okay. 36 00:01:17,873 --> 00:01:19,510 ‫So, here is a simple pattern. 37 00:01:19,510 --> 00:01:22,770 ‫An S3 bucket will have a new file event into Lambda. 38 00:01:22,770 --> 00:01:24,710 ‫And Lambda function will process that file 39 00:01:24,710 --> 00:01:27,643 ‫maybe insert that data into DynamoDB Table 40 00:01:27,643 --> 00:01:30,520 ‫or even a table in RDS database. 41 00:01:30,520 --> 00:01:31,380 ‫Very simple. 42 00:01:31,380 --> 00:01:33,630 ‫Let's see how we can do this in the hands on.