‫So now let's see how we can integrate
‫S3 events notifications with Lambda.
‫So just a reminder on S3 event notifications,
‫it is a way for you to get notified
‫whenever an object is created, removed, restored,
‫when there is a replication happening.
‫You can filter by prefix and by suffix.
‫And the use case is,
‫the classic one is to generate thumbnail images
‫of every image uploaded into Amazon S3.
‫So you have your events into Amazon S3,
‫and S3 can send it to three things,
‫to SNS and from an SNS topic,
‫we can do a fan out pattern to send to multiple SQ-SQ,
‫or we can sent it into an SQ-SQ
‫and have a Lambda function directly read off that SQ-SQ,
‫or we could have an Amazon S3 event notification,
‫directly invoke our Lambda function
‫and this is an asynchronous invocation.
‫And this Lambda function could do
‫whatever it wants with that data,
‫and then in case things go wrong,
‫we can set up a dead-letter queue, for example an SQS,
‫as we've seen from before.
‫So these S3 event notifications typically deliver events
‫in seconds but sometimes can take a minute or longer
‫and so you want to make sure
‫that you're not losing any event notifications,
‫make sure that you enable versioning on your bucket.
‫Otherwise, if two writes on the same object happen
‫at the same exact time, you may get one notification
‫and not two.
‫That's just the small print from the documentation
‫but one worth noting.
‫Okay.
‫So, here is a simple pattern.
‫An S3 bucket will have a new file event into Lambda.
‫And Lambda function will process that file
‫maybe insert that data into DynamoDB Table
‫or even a table in RDS database.
‫Very simple.
‫Let's see how we can do this in the hands on.