func (self *TDynamoDBStore) waitUntilTableIsActive(table string) { checkTimeout, _ := time.ParseDuration(TableCreateCheckTimeout) checkInterval, _ := time.ParseDuration(TableCreateCheckPollInterval) ok, err := annoying.WaitUntil("table active", func() (status bool, err error) { status = false desc, err := self.dynamoServer.DescribeTable(table) if err != nil { return } if desc.TableStatus == TableStatusActive { status = true return } return }, checkInterval, checkTimeout) if !ok { glog.Fatalf("Failed with: %s", err.Error()) } }
func main() { var cfg Config err := gcfg.ReadFileInto(&cfg, "dynamodb.gcfg.local") if err != nil { glog.Fatal(err) } store := MakeDynamoDBStore(cfg.DynamoDemos_AWS.Key, cfg.DynamoDemos_AWS.Secret) store.InitTable() item := MakeItem("some-unique-id", StringAttr("color", "red")) // insert row if ok, err := store.PutItem(item); !ok { glog.Fatalf("Failed to save item %v because of: %v", item, err) } glog.Infof("Item %v saved ", item) // find row savedItem, err := store.GetItem(item.PrimaryKey) if err != nil { glog.Fatalf("Failed to get saved item with pk %s", item.PrimaryKey) } glog.Infof("Got item %#v", savedItem) // find non-existing row _, err = store.GetItem("unknown") if err == nil { glog.Fatalf("Shouldnt get an item with pk %s", "unknown") } else if err.Error() == "Item not found" { glog.Infof("Failed to get non-existent item with err %s", err.Error()) } else { glog.Fatalf("Failed to get non-existent item with unexpected err %s", err.Error()) } // update row updItem := MakeItem("some-unique-id", StringAttr("color", "violet")) if ok, err := store.UpdateItem(updItem); !ok { glog.Fatalf("Failed to update item with unexpected err: %v", err) } // delete row if ok, err := store.DeleteItem(item); !ok { glog.Fatalf("Failed to delete item with unexpected err: %v", err) } store.DestroyTable() }