Skip to content

Instantly share code, notes, and snippets.

@bcambel
Last active February 20, 2018 20:19
Show Gist options
  • Save bcambel/d9bf1021dfd6abd39f32e1d180e513da to your computer and use it in GitHub Desktop.
Save bcambel/d9bf1021dfd6abd39f32e1d180e513da to your computer and use it in GitHub Desktop.
AWS Lambda Function example
'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
/*Print streams as source only data here*/
event.records.forEach((record) => {
console.log(record.kinesisRecordMetadata.sequenceNumber);
console.log(record.kinesisRecordMetadata.subsequenceNumber);
console.log(record.kinesisRecordMetadata.partitionKey);
console.log(record.kinesisRecordMetadata.shardId);
console.log(record.kinesisRecordMetadata.approximateArrivalTimestamp);
});
/* Process the list of records and transform them */
/* The following must be the schema of the returning record
Otherwise you will get processing-failed exceptions
{recordId: <id> , result: 'Ok/Processing/Failed', data: <base64 encoded JSON string> }
*/
const output = event.records.map((record) => ({
/* This transformation is the "identity" transformation, the data is left intact */
recordId: record.recordId,
result: 'Ok',
data: record.data+"Cg==",
}));
console.log(`Processing completed. Successful records ${output.length}.`);
callback(null, { records: output });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment