question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aws dynamodb DocumentClient is not supporting transactions ?

See original GitHub issue

AWS dynamodb document client is not supporting transaction as of date DEC 1 2018 however DynamoDB supporting transactions

let aws=require("aws-sdk");
aws.config.update(
    {
        region:"us-east-1",
        endpoint: "dynamodb.us-east-1.amazonaws.com"	

    }
);
var dynamodb = new  aws.DynamoDB.DocumentClient();


dynamodb.transactWriteItems();
TypeError: dynamodb.transactWriteItems is not a function
    at Object.<anonymous> (/home/varnit/projects/aws_support/index.js:12:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

however when i create an instance of only dynamodb it works var dynamodb = new aws.DynamoDB();

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
imrajdascommented, Dec 16, 2018

SOLUTION Update the aws-sdk package (>2.365) use- var dynamodb = new aws.DynamoDB(); instead of var dynamodb = new aws.DynamoDB.DocumentClient();

3reactions
evgenykireevcommented, Dec 4, 2018

As I temporary solution, I use some private methods of AWS.DynamoDB.DocumentClient. I know it’s a bad practice, but works fine for me.

  1. I collect all transaction items in an array:
....
transactions.push({ Put: params });
....
transactions.push({ Delete: params })

where params are AWS.DynamoDB.DocumentClient params.

  1. I map these transactions to AWS.DynamoDB array
const operationsMapping = {
  Put: 'putItem',
  Delete: 'deleteItem',
  Update: 'updateItem',
};

const dynamoClient = new Dynamo.DocumentClient({ service: dynamoInstance });

// Danger zone - using private methods!
const translator = dynamoClient.getTranslator();
const transactionItems = this.transaction.map((transaction) => {
  const operation = Object.keys(transaction)[0];
  const params = Object.values(transaction)[0];
  const operationType = operationsMapping[operation];

  const request = dynamoClient.service[operationType](params);
  const inputShape = request.service.api.operations[operationType].input;
  const translated = translator.translateInput(params, inputShape);

  return {
    [operation]: translated
  }
});
  1. I execute all as a transaction:
const dynamo = new Dynamo();
const result = await dynamo.transactWriteItems({ TransactItems: transactionItems }).promise();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon DynamoDB Transactions: How it works
With Amazon DynamoDB transactions, you can group multiple actions together and submit them as a single all-or-nothing TransactWriteItems or TransactGetItems ...
Read more >
can't call transactWrite on AWS DynamoDB DocumentClient ...
I have a lambda function (node.js) that needs to perform a transaction on two DynamoDB tables. let ddb = new AWS.DynamoDB.DocumentClient(); ddb.
Read more >
DynamoDB Transactions - The Ultimate Guide (w/ Examples)
Transactions in database world have four basic properties: Atomicity: Guarantees that a transaction is either fully committed or not at all.
Read more >
DynamoDB Transactions: Use Cases and Examples
Amazon's DynamoDB was released in 2012 and has been adding a drumbeat of ... Transactions cost twice as much as a similar non-transaction...
Read more >
Safe List updates with DynamoDB - Medium
Amazon DynamoDB is one of the most versatile and popular services on AWS. ... using the JavaScript AWS-SDK and the DynamoDB DocumentClient:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found