1 個回答
- 最新
- 最多得票
- 最多評論
0
Hi there,
DAX APIs for reading and writing table items are fully compatible with standard DynamoDB APIs. Results should be no different than querying DynamoDB directly.
What happens if you bypass DAX and use the same code directly on the table? My guess is that you will have the same problem. I'm not sure, but my instinct is that there's a logic error with the way you are managing the promises and/or returning map results.
I don't have a DAX cluster running, but I wrote the following Javascript example that you should be able to quickly adapt and test on both DynamoDB and DAX. I also opted for a do...while
loop which I think makes things a bit easier.
var AWS = require('aws-sdk'); // I'm using AWS SSO, so extra steps needed to make this work with SDK: const { fromSSO } = require("@aws-sdk/credential-provider-sso"); async function main(client, params) { let queryResults = []; for (const param of params) { let done = false; do { let data = await client.query(param).promise(); // Per docs below, sometimes query returns empty [] results. // https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html if (data.Items.length > 0) queryResults.push(data.Items); param.ExclusiveStartKey = data.LastEvaluatedKey; done = !('LastEvaluatedKey' in data); } while (!done); } return queryResults; } (async () => { try { // I'm using AWS SSO, so extra steps needed to make this work with SDK: const credentials = await fromSSO({ profile: "personal" })(); var client = new AWS.DynamoDB.DocumentClient({ region: 'us-west-2', credentials: credentials }); let params = []; let param1 = { TableName: 'test-with-sk', Limit: 1, KeyConditionExpression: "pk = :pk", ExpressionAttributeValues: { ":pk": "1" } } params.push(param1); let results = await main(client, params); console.log('Combined query results:\n', results.map(r => JSON.stringify(r))); } catch (e) { console.log(e); } })();
已回答 2 年前
相關內容
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 1 年前