Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BloodShop opened this issue Sep 17, 2024 · 7 comments
Assignees
Labels
closed-for-staleness p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@BloodShop
Copy link

BloodShop commented Sep 17, 2024

  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?

@RanVaknin RanVaknin transferred this issue from aws/aws-sdk Sep 23, 2024
@RanVaknin RanVaknin added the needs-triage This issue or PR still needs to be triaged. label Sep 23, 2024
@aBurmeseDev aBurmeseDev self-assigned this Sep 25, 2024
@aBurmeseDev
Copy link
Member

Hi @BloodShop - thanks for reaching out.

It appears that your questions revolve around services like DDB and DAX, rather than the AWS SDK itself. No worries though as I can internally communicate with the respective service teams to address your concerns.

Additionally, I noticed that your code utilizes the AWS SDK for JavaScript v2, which is currently in maintenance mode. It would be advisable to consider upgrading to the latest aws-sdk-js-v3 version.

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. service-api This issue is due to a problem in a service API, not the SDK implementation. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Sep 25, 2024
@BloodShop
Copy link
Author

Thank you for your help @aBurmeseDev . Please if you may provide example for best practices using daxClient for replacing ddbClient with node (Typescript would be great)

@aBurmeseDev
Copy link
Member

I submitted an internal ticket to service team (ref: P157736270) for guidance and will post back when I hear back.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Sep 27, 2024
@aBurmeseDev
Copy link
Member

Hi @BloodShop - I just heard back from service team member and please see their response addressed to your questions below.

  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.

itemsResult.concat(Items as Array<SomeEntity>); line doesn’t actually modify itemsResult because concat() returns a new array, but it's not reassigned back to itemsResult. I believe you should use push() instead.

Test with concat():

items = []
for (var i=0 ; i<5 ; i++) {
    items.concat(i);
}
console.log(items)

### Output:

[]

Test with push():

items = []
for (var i=0 ; i<5 ; i++) {
    items.push(i);
}
console.log(items)

### Output:

[0, 1, 2, 3, 4]

Please let me know if you continue to see issues. If yes, we'll need logs from your side on what response you are receiving from DAX.

  1. 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?

DynamoDBClient from "@aws-sdk/client-dynamodb" belongs to AWS JS SDK v3 but DAX doesn't support it yet. This would be addressed once DAX supports AWS JS SDK v3.

@aBurmeseDev aBurmeseDev added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 4, 2024
@BloodShop
Copy link
Author

Hey @aBurmeseDev , thanks for your answer.

  1. The example with the concat isn't the problem ofc, it was just a fast code generation.
    The thing is the there is no lastEvaluatedKey retuned in the response, so I cannot handle all the scan/query entities.

  2. I haven't found any "average" documentation that shows how to implement dax with pagination using scan/query commands. On the other hand dynamoDbClient works amazing with the lastEvaluatedKey.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 5, 2024
@aBurmeseDev
Copy link
Member

@BloodShop - here's further response from service team:

DynamoDb returns LastEvaluateKey if we add explicit Limit in the params or if the response size exceed 1MB.

Refer below doc to understand more about the API contract and page limits as DAX always maintain the same contract -
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html

You can try adding Limit to your request params and check if you are able to get LastEvaluatedKey or not.
If not, then please share us the logs on what response you are receiving from DAX.

@aBurmeseDev aBurmeseDev added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 11, 2024
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 16, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

3 participants