Non SST related DynamoDB/Lambda Question I have s...
# help
d
Non SST related DynamoDB/Lambda Question I have some items in my database that look like this
Copy code
pk: 'some-pk'
sk: 'unique-id'
active: true
name: 'cool name'

pk: 'some-pk'
sk: 'another-unique-id'
active: true
name: 'some other name!'
I have another item that’s essentially a variable grouping of those items
Copy code
pk: 'bundle'
sk: 'unique-bundle-name'
bundle: ['unique-id', 'another-unique-id']
I want to “add” a bundle to a customers orders. like…
Copy code
// pseudocode

for (const bundle in bundles) {
  const item = await dynamoDb.get(bundle) // get the item by sk
  await dynamoDb.put({...item, customerId })  // put that value into dynamo
}
Should I just do that? Another thing I could do is get each item, then transact write the whole batch. I mostly don’t know a good way to do something for a “group” of items. Articles/ideas welcome.
a
BatchGetItem and BatchWriteItem will be faster and cheaper, but with the tradeoff of a bit more complexity to your code.
d
I can batch get/write
that’s fine.
d
Adam is spot on. Transactions are more for when it is critical that two things get written together (like say, deleting an item and creating its replacement).
d
Awesome thanks! I just wasn’t exactly sure what the correct approach would be. Appreciate the help both of you!