Mapping Lambda with Kinesis

The final use case in this chapter, but an equally interesting one, Kinesis is just one of another AWS services that provides stream based event sources just as we say with DynamoDB.

Kinesis and Lambda have by far the most exhaustive set of real world use cases; from log processing of streams of log data, to transactional processing, social media analytics and much more!

To get started with Kinesis and Lambda, we follow the same pattern as performed for DynamoDB. We start by creating a Kinesis Stream and mapping it to a particular Lambda function. Lambda then polls the stream for any new records and when it gets a new record (either a single record or in the form of a batch) it invokes the mapped function to execute its code. In the following example we will be using Kinesis to Stream Apache web server logs from a dummy EC2 instance. This log data is then processed by our trusty Lambda function that will send email notifications to a particular set of administrators each time an error is found in the Apache logs.

For simplicity, let's break this use case into two parts: the first is where we set up our dummy EC2 instance with Apache, a Kinesis Stream, and a Kinesis Agent, and the second part will contain the Lambda function code and how to deploy and package it using Apex.