I am trying to do a transact write in DynamoDB. I can't seem to see the error and the error says "validationError, none" which isn't particualarly helpful. The Put for sure works but I am keeping here for completeness in the example
await dynamoDb.transactWrite({
TransactItems: [
{
Put: {
TableName: process.env.TABLE_NAME,
Item: {
pk: compoundId,
sk: interest,
gsi1pk: "#INTEREST",
interest: interest,
id,
},
},
},
{
Update: {
ExpressionAttributeValues: {
":num": 1,
":initial": 0,
},
ExpressionAttributeNames: {
"#tally": "tally",
},
Key: {
PK: shop,
SK: interest,
},
TableName: process.env.TABLE_NAME,
UpdateExpression:
"SET #tally = if_not_exists(tally, :initial) + :num",
},
},
],
});
I'm fairly confident that this is doable per these similar solved questions here:
ItemCollectionMetrics is empty after successful transactWrite using DynamoDB.DocumentClient
Increment the value if it exists, else add a new entry in DynamoDB
The following appears to have worked and the error was adding the ExpressionAttributeNames
await dynamoDb.transactWrite({
TransactItems: [
{
Put: {
TableName: process.env.TABLE_NAME,
Item: {
pk: compoundId,
sk: interest,
gsi1pk: "#INTEREST",
watching: watching,
interest: interest,
id,
},
},
},
{
Update: {
ExpressionAttributeValues: {
":num": 1,
":initial": 0,
},
Key: {
pk: shop,
sk: interest,
},
TableName: process.env.TABLE_NAME,
UpdateExpression:
"SET tally = if_not_exists(tally, :initial) + :num",
},
},
],
});