Error: table has not been registered, in DynamoDB

Error: table has not been registered, in DynamoDB

在为我的本地 dynamodb 使用 pocodynamo 时出现错误,因为 table 尚未注册。我正在尝试进行 crud 操作,但是在将数据插入到本地 dynamodb table 时,出现错误

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

我已经通过以下方式创建了 table:

            //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);

验证 table 已创建并处于活动状态:

                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);

问题不在代码中,而是在 DynamoDB 实例中。我正在使用下载的本地 DynamoDB 数据库并根据 DynamoDB 文档通过命令提示符启动它,但是,当我在 visual studio 中检查 AWS Explorer 时,它说实例已停止。 所以最终对我有用的解决方案是: 1. 如果 DynamoDB 是手动启动的,停止它! 2.确保8000端口空闲 3. 从 AWS Explorer 启动 DynamoDB 你完成了..!

要从 AWS Explorer 启动 DynamoDB: 1. 打开 AWS Explorer 2. Select 区域下拉列表中的本地 (localhost) 3. 右键单击​​ Amazon DynamoDB 和 select "Connect to DynamoDB local" 4. 检查 "Start new DynamoDB Local process"。 5.安装最新版本 6.确保java的路径正确(如果没有安装java,请安装) 7. 点击确定按钮