examples icon indicating copy to clipboard operation
examples copied to clipboard

The DynamoDB / PutItemCommand example returns undefined

Open haydenpitout opened this issue 1 year ago • 3 comments

  • File: aws-dynamodb/pages/api/item.js
  • Row: 28

return res.status(201).json(Item);

Returns undefined even on a successful insert

haydenpitout avatar Aug 31 '22 13:08 haydenpitout

Is the issue from Item? I believe it was working when I tested. Any more information?

leerob avatar Sep 05 '22 19:09 leerob

Hi Lee

Yes, the PutItemCommand does not return the item's attribute values in the same operation, one has to use the ReturnValues parameter to do so. For this reasons Item in { Item } is undefined.

And by the looks of it, for PutItem you only have the option of ALL_OLD for a ReturnValues param ... where if you write a nonexistent item (ie. create a new record), ALL_OLD has no effect.

My workaround (like your earlier cdk v2 version) is to create the Item object before, and pass it into the PutItemCommand, and on successful insert, return the Item object.

Regards, H.

haydenpitout avatar Sep 06 '22 12:09 haydenpitout