1

I have a dynamo table with a partition key of 'shop' and sort key 'item'. I want to use GetItemCommand to find a particular item using this composite key.

  const params = {
  TableName: process.env.DYNAMODB_TABLE_NAME,
  Key: marshall({shop: String(event.pathParameters.shop),
                  item: String(event.pathParameters.item) }),
   };
  const {Item} = await db.send(new GetItemCommand(params));
  console.log("item" + Item);

but it returns undefined

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31
sheffield
  • 11
  • 2

1 Answers1

1

Give this a go

const keys = marshall(
    {   
       shop:event.pathParameters.shop,
       item:event.pathParameters.item 
    })

const params = {
  TableName: process.env.DYNAMODB_TABLE_NAME,
  Key: keys,
};

console.log(params);

try{
  const {Item} = await db.send(new GetItemCommand(params));
  console.log("item" + Item);
}catch(e){
  console.log(e);
}
Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31