Reputation: 111
I try to use Amazons DocumentClient for AWS.dynamodb from the aws-sdk. I also use the Standard node.js VM from Amazon: "64bit Amazon Linux 2016.09 v4.0.1 running Node.js".
On my local machine everything is working fine, but I get the following error message live:
TypeError: AWS.DynamoDB.DocumentClient is not a constructor
And this is the line causing the error:
var docClient = new AWS.DynamoDB.DocumentClient();
I also tried different versions which are used by various tutorials which also fail:
var docClient = new AWS.DynamoDB.DocumentClient({region: "eu-central-1"});
var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
I tried to follow this guide very precisely: https://aws.amazon.com/de/blogs/developer/announcing-the-amazon-dynamodb-document-client-in-the-aws-sdk-for-javascript/
On my local machine it works without a problem. I can connect to the live server or the local dev-server without errors.
AWS.dynamodb without the DocumentClient was also working on the live server, so I guess one option would be to drop DocumentClient alltogether.
I have a package.json which uses the latest aws-sdk:
{
"name": "",
"version": "0.0.1",
"private": true,
"dependencies": {
"aws-sdk": "latest",
[...]
My best guess is, that something is wrong with the node packages. How do I check my assumption and if right, change something about it?
Upvotes: 4
Views: 11560
Reputation: 111
I found the solution! @SwarajGiri pointed in the right direction by suggesting aws-sdk version 2.2.15.
My problem was that I had a npm-shrinkwrap.json in my folder and was not aware that it was overruling the package.json. The aws-sdk version inside the npm-shrinkwrap.json was 2.1.39 which does not include the documentClient(). Document Client was introduced in version 2.2.0
Note that the node.js Elastic Beantalk with DynamoDB tutorial I followed includes this somewhat outdated npm-shrinkwrap.json!
I hope I do not break any rules by answering my own question.
Upvotes: 6