DynamoDB Strongly Consistent Reads, not working all the time

0

In my Node.js application using '@aws-sdk/lib-dynamodb', I'm querying my DynamoDB table with a Local Secondary Index (LSI) and the primary key (PK), while setting ConsistentRead to true. Despite the fact that the desired record was created at least 4 minutes ago according to my log, I am unable to retrieve the specific record I'm querying for. I've double checked on both the PK and Secondary Index and making sure they are correct. I'm really clueless now.

Are there any considerations and use cases for enabling ConsistentRead: true in DynamoDB, and are there any specific scenarios or configurations that need to be in place to ensure consistent reads?

below is my code in Typescript

const queryCommandInput: QueryCommandInput = {
      TableName: process.env.DB_TABLE_NAME,
      IndexName: 'LSI1',
      KeyConditionExpression: '#PK = :PK AND begins_with(#SI1, :SI1)',
      ExpressionAttributeNames: {
        '#PK': 'PK',
        '#SI1': 'SI1',
        // '#CreatedAt': 'CreatedAt',
      },
      ExpressionAttributeValues: {
        ':PK': `MERCHANT_ACC_TRNX#${req.merchantAccId}`,
        ':SI1': `MERCHANT_ACC_TRNX#${trnxDate}#${Number(req.amount)}#false#${req.senderName}`
      },
      ConsistentRead: true,
      Limit: 1
    };
  
    const queryCommand = new QueryCommand(queryCommandInput);
    const queryCommandOutput = await DBClient.send(queryCommand);
    return queryCommandOutput.Items?.[0] as MerchantAccTrnx.Item;
  • While the query seems to be correct, you might want to try searching for a specific record in a very simple format with no parameters or anything. Just to eliminate anything else.

feita há 10 meses465 visualizações
2 Respostas
1

A strongly consistent read is guaranteed to retrieve the latest item view from the table. Some things to check:

  1. You got a 200 Success for the write of the item before querying
  2. No other process is removing the item (stream consumer/TTL)
  3. Be sure to log your variables to ensure they are resolving as you'd expect.

Failing both of those, if you can provide me with reproducible code I would be happy to test it.

profile pictureAWS
ESPECIALISTA
respondido há 10 meses
profile picture
ESPECIALISTA
avaliado há 10 meses
0

I'm sure on 1 & 2 and have added more details into logging to ensure they are resolving as I expect. Will update the details here again when the issue happen again.

FYI this issue only happen once or twice every once in a while and I'm not able to reproduce on local development as well. It is working perfectly as expected when I tested my code on local.

respondido há 10 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas