kwojcicki / amazon-dax-client-v3

AWS JS SDK v3 compatible dax client
Apache License 2.0
5 stars 2 forks source link

Amazon DAX Client for JavaScript AWS sdk-v3

The official version of amazon-dax-client does not work with AWS's javascript sdk-v3.

This is a port of the library that works with sdk-v3.

Installing

The Amazon DAX client only runs from NodeJS, and can be installed using npm:

npm install amazon-dax-client-sdkv3

https://www.npmjs.com/package/amazon-dax-client-sdkv3

Usage and Getting Started

Using Document Client

import AmazonDaxClient from "amazon-dax-client-sdkv3";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";

const documentDaxClient = new AmazonDaxClient({
    client: DynamoDBDocumentClient.from(new DynamoDBClient({
        endpoint: process.env.dax,
        region: 'us-east-2'
    }))
});

const putItem = new PutCommand({
    TableName: 'test',
    Item: {
        CommonName: `${id}`
    }
});

await documentDaxClient.send(putItem);

Using Low Level Client

import AmazonDaxClient from "amazon-dax-client-sdkv3";
import { GetItemCommand } from "@aws-sdk/client-dynamodb";

const daxEndpoint = process.env.dax;
const lowLevelDaxClient = new AmazonDaxClient({
    client: new DynamoDBClient({
        region: 'us-east-1',
        endpoint: daxEndpoint
    })
});

const params = {
    TableName: 'test',
    Key: {
        CommonName: { S: 'example-id' }
    }
};

const getItemCommand = new GetItemCommand(params);
const response = await daxClient.send(getItemCommand);
console.log(response.Item);

You can see more examples under the test folder