-
Notifications
You must be signed in to change notification settings - Fork 634
Closed
Labels
closed-for-stalenessp3This is a minor priority issueThis is a minor priority issueservice-apiThis issue is due to a problem in a service API, not the SDK implementation.This issue is due to a problem in a service API, not the SDK implementation.
Description
-
Trying to figure out how to imlement the pagination of scan and query using
AWS.DynamoDB.DocumentClient
withamazon-dax-client
, cause for now this ain't returning the lastEvaludatedKey on the response. -
Is there any easier way to decorate the
DynamoDBClient
with DAX so I won't need to change in each use case ofDynamoDBClient
toAWS.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 issueThis is a minor priority issueservice-apiThis issue is due to a problem in a service API, not the SDK implementation.This issue is due to a problem in a service API, not the SDK implementation.