Skip to content

cgeduhn/elasticcloud-dynamodb-stream

Repository files navigation

js-standard-style

    Basically a fork of https://github.com/matrus2/dynamodb-stream-elasticsearch

Works only with the standard Elasticsearch >= 7.2

DynamoDB --> Stream --> ElasticSearch

The missing blueprint for AWS Lambda, which reads stream from AWS DynamoDB and writes it to ElasticSearch. Compatible with node 10.x.

Whenever data is changed (modified, removed or inserted) in DynamoDB one can use AWS Lambda function to capture this change and update ElasticSearch machine immediately. Further reading:

Getting Started

Install:

npm install --save elasticcloud-dynamodb-stream

Use it in your lambda:

const { pushStream } = require('elasticcloud-dynamodb-stream');

const trans = async (obj) => {
  // do stuff with obj
  return obj;
};

const ES_ARGS = {
  index: process.env.INDEX,
  host: process.env.ES_ENDPOINT,
  transformFunction: trans, // OPTIONAL
  refresh: false,
};

module.exports.toElastic = async (event, context) => {
  try {
    await pushStream({ event, ...ES_ARGS });
  } catch (e) {
    console.log(e);
    throw e;
  }
  return `Successfully processed ${event.Records.length} records.`;
};

Parameters

Param Description Required
event Event object generated by the stream (pass it as it is and don't modify) required
endpoint Exact url of ElasticSearch instance (it works only with standard ES) (string) required
index The name of ElasticSearch index (string). If not provided will set the same as DynamoDB table name optional
id_fields Array of fields to be used as id in ElasticSearch (array of strings). The order is IMPORTANT! required
refresh Force ElasticSearch refresh its index immediately more here (boolean). Default: true optional
transformFunction A function/promise to transform each record before sending them to ES. Applies to INSERT and UPDATE operations optional
options Additional set of arguments passed to elasticsearch Client see here optional

Authors & Contributors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published