AWS.DynamoDB.DocumentClient — AWS SDK for JavaScript
Examples:
Get items from multiple tables
var params = {
TransactItems: [{
Put: {
TableName : 'Table0',
Item: {
HashKey: 'haskey',
NumAttribute: 1,
BoolAttribute: true,
ListAttribute: [1, 'two', false],
MapAttribute: { foo: 'bar'},
NullAttribute: null
}
}
}, {
Update: {
TableName: 'Table1',
Key: { HashKey : 'hashkey' },
UpdateExpression: 'set #a = :x + :y',
ConditionExpression: '#a < :MAX',
ExpressionAttributeNames: {'#a' : 'Sum'},
ExpressionAttributeValues: {
':x' : 20,
':y' : 45,
':MAX' : 100,
}
}
}]
};
documentClient.transactWrite(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
Calling the transactWrite operation
var params = {
TransactItems: [ /* required */
{
ConditionCheck: {
ConditionExpression: 'STRING_VALUE', /* required */
Key: { /* required */
'<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<AttributeName>': ... */
},
TableName: 'STRING_VALUE', /* required */
ExpressionAttributeNames: {
'<ExpressionAttributeNameVariable>': 'STRING_VALUE',
/* '<ExpressionAttributeNameVariable>': ... */
},
ExpressionAttributeValues: {
'<ExpressionAttributeValueVariable>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<ExpressionAttributeValueVariable>': ... */
},
ReturnValuesOnConditionCheckFailure: ALL_OLD | NONE
},
Delete: {
Key: { /* required */
'<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<AttributeName>': ... */
},
TableName: 'STRING_VALUE', /* required */
ConditionExpression: 'STRING_VALUE',
ExpressionAttributeNames: {
'<ExpressionAttributeNameVariable>': 'STRING_VALUE',
/* '<ExpressionAttributeNameVariable>': ... */
},
ExpressionAttributeValues: {
'<ExpressionAttributeValueVariable>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<ExpressionAttributeValueVariable>': ... */
},
ReturnValuesOnConditionCheckFailure: ALL_OLD | NONE
},
Put: {
Item: { /* required */
'<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<AttributeName>': ... */
},
TableName: 'STRING_VALUE', /* required */
ConditionExpression: 'STRING_VALUE',
ExpressionAttributeNames: {
'<ExpressionAttributeNameVariable>': 'STRING_VALUE',
/* '<ExpressionAttributeNameVariable>': ... */
},
ExpressionAttributeValues: {
'<ExpressionAttributeValueVariable>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<ExpressionAttributeValueVariable>': ... */
},
ReturnValuesOnConditionCheckFailure: ALL_OLD | NONE
},
Update: {
Key: { /* required */
'<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<AttributeName>': ... */
},
TableName: 'STRING_VALUE', /* required */
UpdateExpression: 'STRING_VALUE', /* required */
ConditionExpression: 'STRING_VALUE',
ExpressionAttributeNames: {
'<ExpressionAttributeNameVariable>': 'STRING_VALUE',
/* '<ExpressionAttributeNameVariable>': ... */
},
ExpressionAttributeValues: {
'<ExpressionAttributeValueVariable>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
/* '<ExpressionAttributeValueVariable>': ... */
},
ReturnValuesOnConditionCheckFailure: ALL_OLD | NONE
}
},
/* more items */
],
ClientRequestToken: 'STRING_VALUE',
ReturnConsumedCapacity: INDEXES | TOTAL | NONE,
ReturnItemCollectionMetrics: SIZE | NONE
};
documentclient.transactWrite(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});