0

If I do something like this:

ddbClient.query(someParams).promise()

I will frequently (or possibly always) get this error:

Error: ValidationException: Request object already used

It seems to be because the promise and query have already launched by the time .promise() is called, but that works just fine with the ddb client connecting directly to the database rather than going through dax.

Seems like this may be a bug?

Eli
  • 227
  • 1
  • 3
  • 11
  • Does the API call use both a callback _and_ a promise? That's one way to get the "Request object already used" error. – Throw Away Account Feb 14 '19 at 21:17
  • Actually, I know for a fact that's the problem. You're the guy who wrote the code I'm working on (an advertising platform), and I got this exact error, and fixed it. – Throw Away Account Feb 14 '19 at 21:19

1 Answers1

0

This problem is caused by using both a callback and the .promise() method, like this:

ddbClient.query(someParams, (error, result) => { something } ).promise();

The problem is that every call in the DynamoDB API returns an object of type AWS.Request. The actual HTTP request gets sent only when you call the send() method. But passing a callback implicitly calls send(), and calling promise() implicitly calls it again. You can only call send() once.

The callback has to be turned into a .then() call.

Throw Away Account
  • 2,593
  • 18
  • 21