Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB: ResourceNotFoundException When Creating Table (local)

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?

like image 901
Mac Avatar asked Jan 20 '26 03:01

Mac


1 Answers

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

like image 129
Ashok JayaPrakash Avatar answered Jan 21 '26 22:01

Ashok JayaPrakash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!