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.

Transactions Failing in Lambda

See original GitHub issue

Summary:

I’m using Dynamoose in Node lambdas with version 10.x. I get this error when trying to use transactions.

It works on my local machine with serverless offline but not in a lambda.

TypeError: Cannot read property ‘transactWriteItems’ of undefined at transact (/var/task/node_modules/dynamoose/dist/Dynamoose.js:226:26) at Dynamoose.transaction (/var/task/node_modules/dynamoose/dist/Dynamoose.js:262:13) at process._tickCallback (internal/process/next_tick.js:68:7)

Code sample:

Schema

// Code here
// Showing how transactions are used, para-phrased. 
const role = Role.transaction.create({
    id: roleId,
    tenantId: tenantId,
    owner: body.userId,
  });

  // Save Tenant
  const result = await dynamoose.transaction([tenant, role, ...locations]);

Current output and behavior:

TypeError: Cannot read property ‘transactWriteItems’ of undefined at transact (/var/task/node_modules/dynamoose/dist/Dynamoose.js:226:26) at Dynamoose.transaction (/var/task/node_modules/dynamoose/dist/Dynamoose.js:262:13) at process._tickCallback (internal/process/next_tick.js:68:7)

Expected output and behavior:

For the transaction to be carried out.

Environment:

Lambda Nodejs10.x

Operating System: Lambda Amazon Linux Operating System Version: Node.js version (node -v): Lambda runtime node 10.x NPM version: (npm -v): Dynamoose version: 1.11.1 Dynamoose Plugins: None

Dynamoose Plugins:

  • Yes, I believe that one or multiple 3rd party Dynamoose plugins are effecting this issue
  • [ X] No, I believe this issue is independent of any 3rd party Dynamoose plugins I’m using
  • Unknown, I’m unsure if Dynamoose plugins are effecting this issue
  • [X ] I am not using any Dynamoose plugins

Other information (if applicable):

Type (select 1):

  • [X ] Bug report
  • Feature suggestion
  • [X ] Question
  • Other suggestion
  • Something not listed here

Other:

  • [X ] I have read through the Dynamoose documentation before posting this issue
  • [X ] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • [X ] I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
  • [X ] I have tested the code provided and am confident it doesn’t work as intended
  • [X ] I have ensured that all of my plugins that I’m using with Dynamoose are listed above
  • [X ] I have filled out all fields above
  • [X ] I am running the latest version of Dynamoose

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
dpreacommented, Nov 28, 2019

@fishcharlie Just to circle back for closure in case anyone else runs into this issue when creating micro services with webpack.

The problem was my models lived outside of the directory where my service lived. Importing dynamoose in two places was causing webpack to have two instances in the app. One instance that registered the models, and another to call the transaction.

I fixed this by creating a dbHelper lib that just imports dynamoose, does my env var set up and local checks, and then simply exports the dynamoose instance. Then, everywhere I imported dynamoose, i imported the dbHelper instead and that solved the issue.

Hopefully this helps someone else.

1reaction
fishcharliecommented, Nov 27, 2019

@zeldar Yeah, sorry but I’m not able to run through and help debug that. I’m personally not a fan of build systems like that. They add a lot of complexity and cause the exact problems you are running into now.

At this point tho it doesn’t look like this is a Dynamoose issue. If you want you can try my idea of changing that line to use this.ddb() instead of this.dynamoDB. If you do debug further and determine this is indeed a Dynamoose issue please let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling and automatic retries in AWS Lambda
When you invoke a function, two types of error can occur. Invocation errors occur when the invocation request is rejected before your function...
Read more >
Transactions Failing in Lambda · Issue #695 · dynamoose ...
I get this error when trying to use transactions. It works on my local machine with serverless offline but not in a lambda....
Read more >
How the Saga Pattern manages failures with AWS Lambda ...
In a Saga, the coordinator (database in their case) makes sure that all of the involved transactions are successfully completed. Otherwise, if the...
Read more >
I Processed 558k Transactions on AWS Lambda in 5 Minutes
How I processed over 500 thousand AWS Lambda transactions in 5 minutes ... What will happen in case of failed record is SQS...
Read more >
AWS Lambda Function Synchronization Issues - Stack Overflow
log(err); console.log("transactions committed"); response = { 'statusCode': 200, 'body': ...
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