Skip to content

AWS.DynamoDB.DocumentClient with DAX service scan & query are missing pagination usage/implementation #6507

@BloodShop

Description

@BloodShop
  1. Trying to figure out how to imlement the pagination of scan and query using AWS.DynamoDB.DocumentClient with amazon-dax-client, cause for now this ain't returning the lastEvaludatedKey on the response.

  2. Is there any easier way to decorate the DynamoDBClient with DAX so I won't need to change in each use case of DynamoDBClient to AWS.DynamoDB.DocumentClient instance?

setup:

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import AWS from "aws-sdk";
import { CONFIG } from "../config";
const AmazonDaxClient = require('amazon-dax-client');

const daxClient = new AmazonDaxClient({
  endpoints: [CONFIG.DAX_ENDPOINT],
  maxRetries: 1,
});

export const ddbDocumentClient: AWS.DynamoDB.DocumentClient = new AWS.DynamoDB.DocumentClient({
  service: daxClient,
});

export default new DynamoDBClient({});

The scan operation:

import { AttributeValue, DocumentClient } from "aws-sdk/clients/dynamodb";
import { DB_TABLES } from "../constants/consts";
import { SomeEntity } from "../types";
import { ddbDocumentClient } from "./dynamo";

export const getAccessoryCentersDAL = async (): Promise<Array<SomeEntity>> => {
  let lastEvaluatedKey: Record<string, AttributeValue> | undefined;
  const itemsResult: Array<SomeEntity> = [];

  do {
    const params: DocumentClient.ScanInput = {
      TableName: DB_TABLES.SOME_TABLE,
      ExclusiveStartKey: lastEvaluatedKey,
    } as const;

    const { Items, LastEvaluatedKey } = await ddbDocumentClient.scan(params).promise();

    if (Items?.[0]) {
      itemsResult.concat(Items as Array<SomeEntity>);
    }

    lastEvaluatedKey = LastEvaluatedKey;
  } while (lastEvaluatedKey);

  return itemsResult;
};

Any suggetions?

Metadata

Metadata

Assignees

Labels

closed-for-stalenessp3This is a minor priority issueservice-apiThis issue is due to a problem in a service API, not the SDK implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions