3

I am following the AWS Node.js tutorial, but I cannot get the provided code to work.

Specifically, I am trying to create a “Movies” table on a local instance of DynamoDB and load it with some provided sample data. However, I am receiving ”Cannot do operations on a non-existent table” when I try to create the table, which seems a bit strange.

For my set up, I am running DynamoDB in one console window. The command I am using and output is as follows:

COMPUTERNAME:node-dyna-demo myUserName$ java -Djava.library.path=./dynamodb_local_latest/DynamoDBLocal_lib -jar ./dynamodb_local_latest/DynamoDBLocal.jar -sharedDb
Initializing DynamoDB Local with the following configuration:
Port:   8000
InMemory:   false
DbPath: null
SharedDb:   true
shouldDelayTransientStatuses:   false
CorsParams: *

In a separate console, I am executing the following code:

AWS.config.update({
  credentials: {
    accessKeyId: ‘testAccessId’,
    secretAccessKey: ‘testAccessKey’
  },
  region: 'us-west-2',
  endpoint: 'http://localhost:8000'
})

const dynamodb = new AWS.DynamoDB()
const docClient = new AWS.DynamoDB.DocumentClient()

const dbParams = {
  TableName : "Movies",
  KeySchema: [ … ],
  AttributeDefinitions: [ … ],
  ProvisionedThroughput: { … }
}

dynamodb.createTable(dbParams, function(err, data) {
  if (err) {
    console.error(
      'Unable to create table. Error JSON:',
      JSON.stringify(err, null, 2)
    )
  } else {
    console.log(
      'Created table. Table description JSON:',
      JSON.stringify(data, null, 2)
    )
  }
})

The error I get from execution is:

Unable to create table. Error JSON: {
  "message": "Cannot do operations on a non-existent table",
  "code": "ResourceNotFoundException",
  "time": "2018-01-24T15:56:13.229Z",
  "requestId": "c8744331-dd19-4232-bab1-87d03027e7fc",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 9.419252980728942
}

Does anyone know a possible cause for this exception?

2 Answers 2

4

When Dynamodb local is started without -sharedDb flag, there is a possibility for occurrence of this kind of issue.

In your case local dynamodb is started as expected,

java -Djava.library.path=./dynamodb_local_latest/DynamoDBLocal_lib -jar ./dynamodb_local_latest/DynamoDBLocal.jar -sharedDb

Try the following solutions,

Solution 1: Remove the credential info in in AWS config

AWS.config.update({
  region: 'us-west-2',
  endpoint: 'http://localhost:8000'
})

Reason: If in case dynamodb local is running without -sharedDb flag, it will create new database with respect to that credential.

Solution 2: Creating table using the dynamodb shell (http://localhost:8000/shell/#) and verify whether its created or not using the following command

aws dynamodb list-tables --endpoint-url http://localhost:8000

Sign up to request clarification or add additional context in comments.

1 Comment

It's mentioned in the question that DynamoDB is being started with -SharedDb flag
1

The first answer gave me a hint for my solution. I am using Java in combination with maven. Hopefully my answer can help others. The AWS region might be conflicting. The Java code points to eu-west-1.

amazonDynamoDB = AmazonDynamoDBClientBuilder
               .standard()
               .withEndpointConfiguration(
                 new AwsClientBuilder
                   .EndpointConfiguration("http://localhost:" + 
                       LocalDbCreationRule.port, "eu-west-1"))
               .build();

But my AWS config in my home folder on my local machine on location

~/.aws/config

showed the following:

[default]
region = eu-central-1

I changed the region to eu-west-1, matching the Java code, in my local config and the issue was resolved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.