dynamodb.put().promise() not returning the put object
When you're using promises, you should handle the returned promise object using .then() and .catch(). If you take a look at the documentation, your request should look like this:
dynamoDb.put(params).promise() .then(function(data) { console.log(data); }) .catch(function(err) { console.log(err); });
This will also help you see if you are getting any error (same idea as surrounding an await with try/catch, but clearer syntax)
I have tried ReturnValues: 'ALL_OLD'
but in async await
it has no result.
Here is a part of code:
const answersParams = { TableName: ANSWERS_TABLE, Item: { answersId, answers, userId, quizId, }, ReturnValues: 'ALL_OLD', }; try { const createdAnswres = await db.put(answersParams).promise(); return { statusCode: 201, body: JSON.stringify(createdAnswres && createdAnswres.Item), }; } catch (error) { return { statusCode: 500, body: 'failed to save user answers', }; } }
So I had to add another request to db:
const createdAnswres = await db.get({ TableName: ANSWERS_TABLE, Key: { answersId }, }) .promise();