2
votes

I have locally running DynamoDB and create a table using the shell( localhost:8000/shell/).

Can confirm with the following code:

var params = {
  ExclusiveStartTableName: 'STRING_VALUE',
  Limit: 10
};
dynamodb.listTables(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

outputs

{"TableNames":["myTable"]}

However when I call getItem/PutItem from PHP code it throws the following error

[Mon Dec 14 11:22:48.266930 2015] [:error] [pid 12] [client 10.0.2.2:58042] PHP Fatal error: Uncaught Aws\DynamoDb\Exception\ResourceNotFoundException: AWS Error Code: ResourceNotFoundException, Status Code: 400, AWS Request ID: 8de599f1-7aa6-4147-b2f8-b3acc74b09da, AWS Error Type: client, AWS Error Message: Cannot do operations on a non-existent table, User-Agent: aws-sdk-php2/2.8.24 Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.14\n thrown in /opt/lib/aws/sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

And this is how I create the client

$this->client = DynamoDbClient::factory(array(
    'key' => 'YOUR_KEY', 
    'secret' => 'YOUR_SECRET', 
    'profile' => 'default',
    'region'  => 'us-west-2',
    //'version' => '2012-08-10',
    'endpoint'=> 'http://localhost:8000',
    //'debug'   => true
));

If the endpoint were wrong, client creation itself would have thrown error but in this case tables are not getting created as per PHP

echo "List of tables";
$iterator = $this->client->()->getIterator('ListTables');
foreach ($iterator as $tableName) {
    echo $tableName . "\n";
}

prints nothing.

1
What parameters odes the JavaScript client have (region, and others), is from a browser, and how are you starting up DynamoDBLocal (what command line arguments)?mkobit
The JS api did not have any region info but while starting the dynamoDB service I did not mention -sharedDb which according to the documentation is hardcoded to us-west-2. I tried mentioning -sharedDb during launch also but did not work despite JS api confirming that it existsNeil
Just realized I had a typo in the endpoint URL. It seems to be working now. I was expecting it will show some error for invalid URL instead of just saying table does not exists.Neil

1 Answers

1
votes

I have just answered a similar question here: https://stackoverflow.com/a/40806393/1061798

Check how you are starting dynamoDB. You need to add a -sharedDb flag as described in my answer in the link above