Using AWS Lambda with Amazon Kinesis without Batch Item Handling

Using AWS Lambda with Amazon Kinesis without Batch Item Handling.

The Lambda function retrieves Kinesis Records from the event parameter that it receives. The function retrieves Kinesis payload, decode from Base64 and log them to cloudwatch. The function processes Kinesis Records without batch item handling.

Select language:

Usage Example with Node:

Consuming Kinesis event with Lambda using JavaScript without batch item handling.

exports.handler = async (event, context) => {
  for (const record of event.Records) {
    try {
      console.log(`Processed Kinesis Event - EventID: ${record.eventID}`);
      const recordData = await getRecordDataAsync(record.kinesis);
      console.log(`Record Data: ${recordData}`);
      // TODO: Do interesting work based on the new data
    } catch (err) {
      console.error(`An error occurred ${err}`);
      throw err;
    }
  }
  console.log(`Successfully processed ${event.Records.length} records.`);
};

async function getRecordDataAsync(payload) {
  var data = Buffer.from(payload.data, "base64").toString("utf-8");
  await Promise.resolve(1); //Placeholder for actual async work
  return data;
}

                                                      



Created by:

Mohammed Tomeh

Mohammed Tomeh

Cloud Application Architect at AWS

Follow on LinkedIn

Ananthan Rudran

Ananthan Rudran

Solutions Architect Architect at AWS

Follow on LinkedIn

Umang Aggarwal

Umang Aggarwal

Technical Account Manager @ AWS

Follow on LinkedIn

Jan Richter

Jan Richter

Cloud Architect at AWS

Follow on LinkedIn