Reputation: 4367
I'm using dynamoDB-local with nodejs code.
I have the following code:
var aws = require("aws-sdk")
aws.config.update({"accessKeyId": "aaa",
"secretAccessKey": "bbb",
"region": "us-east-1"})
var awsdb = new aws.DynamoDB({ endpoint: new aws.Endpoint("http://localhost:8000") });
awsdb.createTable({
TableName: 'myTbl',
AttributeDefinitions: [
{ AttributeName: 'aaa', AttributeType: 'S' },
],
KeySchema:[
{ AttributeName: 'aaa', KeyType: 'HASH' }
]
}, function() {
awsdb.listTables(function(err, data) {
console.log(data)
});
});
But it isn't creating the table. I'm getting { TableNames: [] }
in logs.
err is null.
Upvotes: 1
Views: 3586
Reputation: 862
It seems like you are missing the required ProvisionedThroughput parameter in the CreateTable request. So what is happening is the CreateTable returns a validation error and ListTables executes successfully without returning any tables (The "err" variable in your code seems to be for the ListTables call)
E.g. the following is working for me
var aws = require("aws-sdk")
aws.config.update({"accessKeyId": "aaa",
"secretAccessKey": "bbb",
"region": "us-east-1"})
var awsdb = new aws.DynamoDB({ endpoint: new aws.Endpoint("http://localhost:8000") });
awsdb.createTable({
TableName: 'myTbl',
AttributeDefinitions: [
{ AttributeName: 'aaa', AttributeType: 'S' },
],
KeySchema:[
{ AttributeName: 'aaa', KeyType: 'HASH' }
],
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},
}, function(err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else {
awsdb.listTables(function(err, data) {
console.log(data)
});
}
});
Upvotes: 3
Reputation: 2169
After you issue a createTable you have to wait until the table is effectively created. Once the table is created it will appear in your listTables call. You can wait by using the describeTable call.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property
CreateTable is an asynchronous operation. Upon receiving a CreateTable request, DynamoDB immediately returns a response with a TableStatus of CREATING.
You can use the DescribeTable API to check the table status.
Upvotes: 0