Giter Club home page Giter Club logo

building-opensearch-index-from-dynamo-db's Introduction

Lambdas for OpenSearch with a DynamoDb source

Check out the blog post explaining more about this setup here: https://instil.co/blog/opensearch-with-dynamodb/

This contains lambdas to help handle OpenSearch with DynamoDb

Indexing from a DynamoDb Stream

Inside the index-stream directory you'll find the code for indexing remove/insert/modify stream events from DynamoDB. If you are unsure on how to set up a dynamo stream then check this out https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html#Streams.Enabling

Or if you are using CDK, here is an example of a table with a stream event:

const userTable = new Table(this, "UserTable", {
  tableName: "user-table",
  billingMode: BillingMode.PAY_PER_REQUEST,
  partitionKey: {name: "partitionKey", type: AttributeType.STRING},
  sortKey: {name: "sortKey", type: AttributeType.STRING},
  pointInTimeRecovery: true,
  stream: StreamViewType.NEW_IMAGE // This is the important line!
});

Assuming you have set up your Lambda in CDK (userTableStreamProcessorLambdaFunction), you then just need to tell the stream to head off to that lambda:

  userTableStreamProcessorLambdaFunction.addEventSource(new DynamoEventSource(this.userTable, {
    startingPosition: StartingPosition.TRIM_HORIZON,
    batchSize: 1,
    retryAttempts: 3
  }));

PLEASE NOTE: you must give the correct privileges to this lambda:

    openSearchDomain.grantIndexReadWrite("user-index", userTableStreamProcessorLambdaFunction);

Deleting an index

Inside the delete-index folder you will find another lambda. This one can be set up to have a trigger, however I would recommend just manually triggering it from the console when you need to.

PLEASE NOTE: you must give the correct privileges to this lambda:

    openSearchDomain.grantIndexReadWrite("user-index", deleteIndexLambdaFunction);

Indexing existing data

Inside the index-data folder you will find another lambda. This one can be set up to have a trigger, however I would recommend just manually triggering it from the console when you need to. It has been set up to allow an optional date range if you wish to only index data inside a that range (provided you have some field on your object like createdDate or updatedOn etc). Otherwise the lambda will index all the data.

PLEASE NOTE: you must give the correct privileges to this lambda:

  openSearchDomain.grantIndexReadWrite("user-index", indexExistingDataLambdaFunction);
  userTable.grantReadData(indexExistingDataLambdaFunction);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.