0

Thank you! for taking time to read this post.

I an new to JS and stuck in a callback issue related to promise() when querying AWS DAX. There is a post (using the .promise() call on a dax-services dynamodb document client returns error: Error: ValidationException: Request object already used) related to this issue but am not able to follow the answer.

I also visited below page but got stuck as the page does not provide a sample for client.send(command) https://www.npmjs.com/package/@aws-sdk/client-dax

I keep getting below error: DaxClientError: ValidationException: Request object already used.

Can you please help correcting below code and with explanation to the solution?

I will truly appreciate your help. I spent an entire day on this but did not make any progress.

const express = require('express');
const AWS = require('aws-sdk');
const AmazonDaxClient = require('amazon-dax-client');

var region = "us-west-2";

AWS.config.update({
  region: region
});

const myendpoint = "daxs://mydax.xxxx.dax-clusters.us-west-2.amazonaws.com";
const dax = new AmazonDaxClient({endpoints: [myendpoint], region: region});

// If using AWS.DynamoDB.DocumentClient ...
const doc = new AWS.DynamoDB.DocumentClient({service: dax});

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();

app.get('/', (req, res) => {
  res.send('Hello World');
});

app.get('/readreview', async (req, res) => {
  
try{

var myresult='empty';
    
var params = {
            TableName: 'test',
            Key:{
                "id": 'p12',
                "key": 'description'
            }
        };

await doc.get(params, function(err, data) {
        if (err) {
            console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
            } else {
              myresult=data;
           console.log("@@@@@@@@@"+data);
        }
    }).promise();

    res.send(myresult);
}

catch (e) {
  console.log(e);
}
});

app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);

Thank you!

sandeep
  • 51
  • 1
  • 1
  • 6

0 Answers0