Coder Social home page Coder Social logo

cdk-dynamodb-meilisearch-typescript's Introduction

Welcome to CDK DynamoDB Search

This is an Amazon DynamoDB helper written in TypeScript enabling full text search using Meilisearch on top of Amazon Web Services Cloud Development Kit (AWS CDK)

How does it work?

This package is a wrapper around Amazon DynamoDB table that listens to its ("INSERT", "MODIFY", "REMOVE") events using Amazon DynamoDB Streams.

Insert event

When an item/items is inserted in the table, an "INSERT" event is triggered, an AWS Lambda function listens to this event and inserts a document/documents based on the received record/records using Meilisearch Client add documents.

Modify event

When an item/items is inserted in the table, an "MODIFY" event is triggered, an AWS Lambda function listens to this event and updates a document/documents based on the received record/records using Meilisearch Client update documents.

Remove event

When an item/items is inserted in the table, an "REMOVE" event is triggered, an AWS Lambda function listens to this event and deletes a document/documents based on the received record/records primary keys using Meilisearch Client delete documents.

Modes

Currently the package supports two modes Cloud and Self-hosted:

Cloud

Uses Meilisearch Cloud service managed by Meilisearch team. You can check out Meilsearch Cloud pricing to get started on using the Meilisearch Cloud mode jump to Getting started with Meilisearch Cloud mode section

Self-hosted

Uses the official Docker image from Docker Hub hosted in AWS Fargate behind an AWS Application Load Balancer. You can calculate the cost here to get started on using the Meilisearch Cloud mode jump to Getting started with Meilisearch Hosted mode section

Getting started

Getting started with Meilisearch Cloud mode - View example

  1. Install the package
  • Using NPM npm install cdk-dynamodb-search
  • Using Yarn yarn add cdk-dynamodb-search
  1. Get the host and the API key Create an account in Meilisearch Cloud and get the host URL and the API key from your settings.

  2. Import the package Import "WithCloudSearch" into the stack containing the table definition - Required

import { WithCloudSearch } from "cdk-dynamodb-search";
  1. Wrap your DynamoDB table with the WithSearch helper - Required
new WithCloudSearch(this,"MySearch", {
	// my_table: dynamodb.Table - Required
	table: my_table  // Add here!!!
});
  1. Add the search API key (will be used as the Meilisearch master key - Required
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    // apiKey: string - Required	
    apiKey: "MY_SUPER_SECRET_KEY" // Add here!!!
  }
});
  1. Add the search host URL - Required
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    apiKey: "MY_SUPER_SECRET_KEY"
  },
  provider: {
    // host: string - Required
    host: "https://...your-meilisearch-host" // Add here!!!
  }
});
  1. Deploy the solution - Required npx cdk deploy

That's it that was the minimal usage.

Create an item in your table and visit the host URL to see that item has been created successfully.

Further customization

If you want further customization you can customize the params:

  1. Set the Meilisearch search index - Optional
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    apiKey: "MY_SUPER_SECRET_KEY",
    index: "my-search-index"
  },
  provider: {
    // host: string - Optional
    host: "https://...your-meilisearch-host" // Add here!!!
  }
});

Getting started with Meilisearch Hosted mode - View example

  1. Install the package
  • Using NPM npm install cdk-dynamodb-search
  • Using Yarn yarn add cdk-dynamodb-search
  1. Import the package Import "WithCloudSearch" into the stack containing the table definition - Required
import { WithHostedSearch } from "cdk-dynamodb-search";
  1. Wrap your DynamoDB table with the WithSearch helper - Required
new WithHostedSearch(this,"MySearch", {
  // my_table: dynamodb.Table - Required
  table: my_table  // Add here!!!
});
  1. Add the search API key (will be used as the Meilisearch master key - Required
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    // apiKey: string - Required - Create your own key
    apiKey: "MY_SUPER_SECRET_KEY" // Add here!!!
  }
});
  1. Deploy the solution - Required npx cdk deploy

That's it that was the minimal usage.

Create an item in your table and visit the host URL to see that item has been created successfully.

Further customization

If you want further customization you can customize the params:

  1. Set the Meilisearch search index - Optional
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    apiKey: "MY_SUPER_SECRET_KEY",
    index: "my-search-index"
  },
  provider: {
    // host: string - Optional
    host: "https://...your-meilisearch-host" // Add here!!!
  }
});
  1. Set the container CPU compute power - Optional
  • Import ComputeValue
import { 
  WithHostedSearch 
  ComputeValue // Add here!!!
} from "cdk-dynamodb-search";
  • Add the container CPU compute power
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    apiKey: "MY_SUPER_SECRET_KEY",
    index: "my-search-index"
  },
  // container: WithSearchProps["ContainerProps"] - Optional
  container: {
    // cpu: ComputeValue - Optional - default 256
    cpu: ComputeValue.v512 // Add here!!!
  }
});
  1. Set the container memory in megabytes - Optional
  • Import ComputeValue
import { 
  WithHostedSearch 
  ComputeValue // Add here!!!
} from "cdk-dynamodb-search";
  • Add the container memory
new WithCloudSearch(this,"MySearch", {
  table: my_table,
  search: {
    apiKey: "MY_SUPER_SECRET_KEY",
    index: "my-search-index"
  },
  // container: WithSearchProps["ContainerProps"] - Optional
  container: {
    // memory: ComputeValue - Optional - default 512
    memory: ComputeValue.v1024 // Add here!!!
  }
});

Props

WithCloudSearch

type CloudSearchProps = {
  apiKey: string;
  index?: string;
};
type ProviderProps = {
  host: string;
};
interface WithCloudSearchProps {
  table: dynamodb.Table;
  search: SearchProps;
  provider: ProviderProps;
}

WithHostedSearch

type HostedSearchProps = {
  apiKey: string;
  index?: string;
};
enum ComputeValue {
  v256 = 256,
  v512 = 512,
  v1024 = 1024,
  v2048 = 2048,
  v4096 = 4096,
}
type ContainerProps = {
  memoryLimitMiB: ComputeValue.v512;
  cpu: ComputeValue.v256;
};
interface WithHostedSearchProps {
  table: dynamodb.Table;
  search: SearchProps;
  provider: ProviderProps;
}

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • npx cdk deploy deploy this stack to your default AWS account/region
  • npx cdk diff compare deployed stack with current state
  • npx cdk synth emits the synthesized CloudFormation template

cdk-dynamodb-meilisearch-typescript's People

Contributors

soflass1293 avatar soflass avatar

Stargazers

Hamza Mehri avatar

Watchers

Hamza Mehri avatar  avatar

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.