Getting error as the table has not been registered while using pocodynamo for my local dynamodb. I'm trying to have crud operation but while inserting data to the local dynamodb table, I'm getting an error as
System.ArgumentNullException: "Tabel has not been registered: Todo. Parameter name: table"
var awsDb = new AmazonDynamoDBClient("access key", "secret key", new AmazonDynamoDBConfig
{
ServiceURL = "http://localhost:8000",
});
var db = new PocoDynamo(awsDb);
db.InitSchema();
var todos = 100.Times(i => new Todo { Content = "TODO " + i, Order = i });
db.PutItems(todos);//getting error on this line
I have already created a table by:
//AWSSDK
var request = new CreateTableRequest
{
TableName = "Todo",
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement("Id", KeyType.HASH),
},
AttributeDefinitions = new List<AttributeDefinition>
{
new AttributeDefinition("Id", ScalarAttributeType.N),
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 10,
WriteCapacityUnits = 5,
}
};
awsDb.CreateTable(request);
Verify that table is created and in Active state:
var startAt = DateTime.UtcNow;
var timeout = TimeSpan.FromSeconds(60);
do
{
try
{
var descResponse = awsDb.DescribeTable("Todo");
if (descResponse.Table.TableStatus == DynamoStatus.Active)
{
Console.WriteLine("table Todo is Active");
break;
}
Thread.Sleep(TimeSpan.FromSeconds(2));
}
catch (ResourceNotFoundException)
{
Console.WriteLine("resource not found");
// DescribeTable is eventually consistent. So you might get resource not found.
}
if (DateTime.UtcNow - startAt > timeout)
throw new TimeoutException("Exceeded timeout of {0}".Fmt(timeout));
} while (true);
The problem was not in code, but with DynamoDB instance. I was using the downloaded local DynamoDB database and started it by command prompt as per DynamoDB documentation, However, when I checked AWS Explorer in visual studio, it says instance was stopped. So final the solution worked for me was: 1. If DynamoDB was started manually, Stop it! 2. Ensure that port 8000 is free 3. start DynamoDB from AWS Explorer You are done..!
To start DynamoDB from AWS Explorer: 1. Open AWS Explorer 2. Select local (localhost) from the dropdown of Region 3. Right click on Amazon DynamoDB and select "Connect to DynamoDB local" 4. Check "Start new DynamoDB Local process". 5. Install the latest version 6. Ensure that the path to java is correct (if java is not installed, install it) 7. Click on OK button