public string InitTableProcess()
        {
            List <string> currentTables = DynamoClient.ListTables().TableNames;

            if (!currentTables.Contains("DVD"))
            {
                var createTableRequest = new CreateTableRequest
                {
                    TableName             = "DVD",
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 1,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Title",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "ReleaseYear",
                            KeyType       = "RANGE"
                        },
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition()
                        {
                            AttributeName = "Title", AttributeType = "S"
                        },
                        new AttributeDefinition()
                        {
                            AttributeName = "ReleaseYear", AttributeType = "N"
                        }
                    }
                };


                CreateTableResponse createTableResponse = DynamoClient.CreateTable(createTableRequest);

                while (createTableResponse.TableDescription.TableStatus != "ACTIVE")
                {
                    System.Threading.Thread.Sleep(5000);
                }
                return(createTableResponse.TableDescription.TableStatus.Value.ToString());
            }
            return("Empty Hand");
        }
        public void SingleSuccessfulRequest()
        {
            ThreadPool.QueueUserWorkItem(UDPListener);
            CSMTestUtilities testUtils = new CSMTestUtilities
            {
                Service            = "DynamoDB",
                ApiCall            = "ListTables",
                AttemptCount       = 1,
                Domain             = "dynamodb.us-east-1.amazonaws.com",
                Region             = "us-east-1",
                HttpStatusCode     = 200,
                MaxRetriesExceeded = 0,
                StashCount         = 3
            };
            AmazonDynamoDBConfig config = new AmazonDynamoDBConfig
            {
                RegionEndpoint = Amazon.RegionEndpoint.USEast1
            };
            AmazonDynamoDBClient client = new AmazonDynamoDBClient(config);

            client.ListTables(new ListTablesRequest {
            });
            Thread.Sleep(10);
            testUtils.EndTest();
            testUtils.Validate(stash);
        }
예제 #3
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonDynamoDBConfig config = new AmazonDynamoDBConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonDynamoDBClient client = new AmazonDynamoDBClient(creds, config);

            ListTablesResponse resp = new ListTablesResponse();

            do
            {
                ListTablesRequest req = new ListTablesRequest
                {
                    ExclusiveStartTableName = resp.LastEvaluatedTableName
                    ,
                    Limit = maxItems
                };

                resp = client.ListTables(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.TableNames)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.LastEvaluatedTableName));
        }
예제 #4
0
        public async Task <IEnumerable <Presentation> > GetAllContent(string path, string pattern)
        {
            var list = new List <Presentation>();

            if (null == _client)
            {
                return(list);
            }

            var tables = _client.ListTables().TableNames;

            if (!tables.Any())
            {
                //presentations table not found, create it
                var response = await _client.CreateTableAsync(new CreateTableRequest
                {
                    TableName             = "Presentation",
                    ProvisionedThroughput = new ProvisionedThroughput {
                        ReadCapacityUnits = 3, WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Title",
                            KeyType       = KeyType.HASH
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition {
                            AttributeName = "Title", AttributeType = ScalarAttributeType.S
                        }
                    }
                });

                var created = response.TableDescription.TableName.Equals("Presentation");

                var ctx      = new DynamoDBContext(_client);
                var contents = GetAllLocalContent(ConfigurationManager.AppSettings["path"], ConfigurationManager.AppSettings["pattern"]);
                foreach (var presentation in contents)
                {
                    await ctx.SaveAsync(presentation);
                }

                return(contents);
            }

            var context = new DynamoDBContext(_client);
            var query   = context.ScanAsync <Presentation>(new List <ScanCondition> {
                new ScanCondition("Image", ScanOperator.BeginsWith, "ms-appx")
            });

            while (!query.IsDone)
            {
                list = await query.GetNextSetAsync();
            }

            return(list);
        }
        private void checknCrt()
        {
            //check and create bucket
            string inputBucketName = "minjikim306bookrepo";

            createBucket(inputBucketName);

            //check and create tables
            var tableResponse = client.ListTables();

            if (!tableResponse.TableNames.Contains(tableName))
            {
                bool res = createTable();
                if (res)
                {
                    //MessageBox.Show("Successfully Registered!");
                    Console.WriteLine("Table creation successful");
                }
                else
                {
                    Process p = Process.GetCurrentProcess();
                    p.Kill();
                }
            }
        }
예제 #6
0
        public void TestDynamoDbClient()
        {
            AWSSDKHandler.RegisterXRayForAllServices(_path);
            // IAmazonDynamoDb will be registered. All new instances of AmazonServiceClient will be automatically registered.

            using (var client = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1))
            {
                string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
                CustomResponses.SetResponse(client, null, requestId, true);

                _recorder.BeginSegment("test", TraceId);
#if NET45
                client.ListTables();
#else
                client.ListTablesAsync().Wait();
#endif
                var segment    = TraceContext.GetEntity();
                var subsegment = segment.Subsegments[0];
                _recorder.EndSegment();

                Assert.AreEqual(segment.Subsegments.Count, 1);
                Assert.AreEqual(subsegment.Name, "DynamoDBv2");
                Assert.AreEqual(subsegment.Aws["region"], RegionEndpoint.USEast1.SystemName);
                Assert.AreEqual(subsegment.Aws["operation"], "ListTables");
                Assert.AreEqual(requestId, subsegment.Aws["request_id"]);
                Assert.AreEqual("aws", subsegment.Namespace);
            }
        }
예제 #7
0
        private async void creatingTable()
        {
            if (string.IsNullOrEmpty(TxtUserEmail.Text) || string.IsNullOrEmpty(TxtPassword.Password))
            {
                MessageBox.Show("Fields can't be empty!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                client  = new AmazonDynamoDBClient();
                context = new DynamoDBContext(client);
                List <string> currentTables = client.ListTables().TableNames;


                if (!currentTables.Contains(tableName))
                {
                    await CreateUserTable(client, tableName);
                    await saveUser(context);
                }
                else
                {
                    await saveUser(context);
                }
                BtnLogin.IsEnabled = true;
            }
        }
예제 #8
0
        public static async Task CreateUserTable(AmazonDynamoDBClient client, string tableName)
        {
            var tableResponse = client.ListTables();

            if (!tableResponse.TableNames.Contains(tableName))
            {
                await Task.Run(() =>
                {
                    client.CreateTable(new CreateTableRequest
                    {
                        TableName             = "Users",
                        ProvisionedThroughput = new ProvisionedThroughput {
                            ReadCapacityUnits = 5, WriteCapacityUnits = 5
                        },
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement
                            {
                                AttributeName = "UserEmail",
                                KeyType       = KeyType.HASH
                            }
                        },
                        AttributeDefinitions = new List <AttributeDefinition>
                        {
                            new AttributeDefinition {
                                AttributeName = "UserEmail", AttributeType = ScalarAttributeType.S
                            }
                        }
                    });
                    Thread.Sleep(5000);
                });
            }
        }
예제 #9
0
        private void QueryBooksList(DynamoDBContext context)
        {
            string        tabName       = "BookShelf";
            List <string> currentTables = client.ListTables().TableNames;

            if (currentTables.Contains(tabName))
            {
                IEnumerable <BookShelf> ownedBooksResult;
                ownedBooksResult = context.Scan <BookShelf>(
                    new ScanCondition("UserEmail", ScanOperator.Equal, loggedinUserId));
                Console.WriteLine("List retrieved " + ownedBooksResult);
                foreach (var result in ownedBooksResult)
                {
                    if (result != null)
                    {
                        BookShelf newShelf = new BookShelf()
                        {
                            BookId    = result.BookId,
                            BookTitle = result.BookTitle,
                            IsActive  = result.IsActive,
                            ISBN      = result.ISBN,
                            Author1   = result.Author1,
                            Author2   = result.Author2,
                            Author3   = result.Author3,
                            UserEmail = result.UserEmail,
                        };

                        booksList.Add(newShelf);
                    }
                    lstBooks.ItemsSource = null;
                    lstBooks.ItemsSource = booksList;
                }
            }
        }
예제 #10
0
        private void GetSnapshots(DynamoDBContext context)
        {
            List <string> currentTables = client.ListTables().TableNames;

            if (currentTables.Contains("Snapshot"))
            {
                IEnumerable <Snapshot> ownedBooksResult;
                Console.WriteLine("Running scan to get owned books");
                ownedBooksResult = context.Scan <Snapshot>(
                    new ScanCondition("Email", ScanOperator.Equal, userEmail));
                Console.WriteLine("List retrieved " + ownedBooksResult);
                foreach (var result in ownedBooksResult)
                {
                    if (result != null)
                    {
                        Snapshot snap = new Snapshot()
                        {
                            SnapshotId = result.SnapshotId,
                            BookTitle  = result.BookTitle,
                            Email      = result.Email,
                            DateTime   = result.DateTime,
                            LastPage   = result.LastPage,
                        };

                        snapshotList.Add(snap);
                    }

                    lstSnapshot.ItemsSource = snapshotList;
                }
            }
        }
예제 #11
0
        public static Table CreateDynamoDbTable(string user, string pass)
        {
            var tableName = string.Format("Rates{0}", DateTime.Now.ToString("yyyyMMddHHmmss"));

            var client = new AmazonDynamoDBClient(new BasicAWSCredentials(user, pass), RegionEndpoint.USEast1);

            Console.WriteLine("Getting list of tables");
            List <string> currentTables = client.ListTables().TableNames;

            Console.WriteLine("Number of tables: " + currentTables.Count);
            if (!currentTables.Contains("blah"))
            {
                var request = new CreateTableRequest
                {
                    TableName            = tableName,
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Age",
                            AttributeType = "N"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = "N"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Age",
                            KeyType       = "Hash"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "Id",
                            KeyType       = "Range"
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 10,
                        WriteCapacityUnits = 5
                    },
                };

                var response = client.CreateTable(request);

                Console.WriteLine(string.Format("Table {0} created with request ID: {1}", tableName, response.ResponseMetadata.RequestId));
                int var = 1;
            }

            var table = Table.LoadTable(client, tableName);

            System.Threading.Thread.Sleep(10000);
            return(table);
        }
예제 #12
0
 private static void ListTables(AmazonDynamoDBClient client)
 {
     Console.WriteLine("Tables:\n--------\n");
     foreach (var x in client.ListTables().TableNames)
     {
         Console.WriteLine(x + "\n");
     }
 }
예제 #13
0
        private void CreateCameraTable(string tblName)
        {
            List <string> currentTables = client.ListTables().TableNames;

            if (!currentTables.Contains(tblName))
            {
                CreateTableRequest createRequest = new CreateTableRequest
                {
                    TableName            = tblName,
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "camId",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "location",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "quality",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>()
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "camId",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "camId",
                            KeyType       = "RANGE"
                        }
                    },
                };

                createRequest.ProvisionedThroughput = new ProvisionedThroughput(1, 1);

                CreateTableResponse createResponse;
                try
                {
                    createResponse = client.CreateTable(createRequest);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error: failed to create the new table; " + ex.Message);

                    return;
                }
            }
        }
예제 #14
0
        private static string GetTableName()
        {
            var tables = client.ListTables().TableNames;

            Assert.AreNotEqual(0, tables.Count);
            var tableName = tables.First();

            return(tableName);
        }
예제 #15
0
        private void CreateTable(string tabNam, string hashKey)
        {
            client = new AmazonDynamoDBClient();
            var tableResponse = client.ListTables();

            if (!tableResponse.TableNames.Contains(tabNam))
            {
                MessageBox.Show("Shelf doesn't exist, creating shelf " + tabNam);
                client.CreateTable(new CreateTableRequest
                {
                    TableName             = tabNam,
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 3,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = hashKey,
                            KeyType       = KeyType.HASH
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition {
                            AttributeName = hashKey, AttributeType = ScalarAttributeType.S
                        }
                    }
                });

                bool isTableAvailable = false;
                while (!isTableAvailable)
                {
                    Console.WriteLine("Waiting for table to be active...");
                    Thread.Sleep(5000);
                    var tableStatus = client.DescribeTable(tabNam);
                    isTableAvailable = tableStatus.Table.TableStatus == "ACTIVE";
                }
                MessageBox.Show($"Shelf {tabNam} Created Successfully!");
                SaveBookinShelf();
                enableBtns();
                //resetBtns();
            }
            else
            {
                MessageBox.Show($"{tabNam} exist already!, Adding {txtTitle.Text} book in the shelf");
                SaveBookinShelf();
                //resetBtns();
                enableBtns();
            }
        }
예제 #16
0
        protected void DeleteTable(string tableName)
        {
            var response = Client.ListTables();

            if (!response.TableNames.Contains(tableName))
            {
                return;
            }

            Client.DeleteTable(new DeleteTableRequest {
                TableName = tableName
            });
        }
예제 #17
0
        public static void ClassSetUp(TestContext context)
        {
            DBConfig = new AmazonDynamoDBConfig {
                ServiceURL = "http://127.0.0.1:8000"
            };
            Client = new AmazonDynamoDBClient(DBConfig);

            var listTableResponse = Client.ListTables();

            if (listTableResponse.TableNames.Contains(TestTableName))
            {
                return;
            }
            CreateTable();
        }
        public void Init()
        {
            List <string> currentTables = _client.ListTables().TableNames;

            if (!currentTables.Contains("Reservation"))
            {
                var createTableRequest = new CreateTableRequest
                {
                    TableName             = "Reservation",
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 1,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Fullname",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "DateTime",
                            KeyType       = "RANGE"
                        },
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition()
                        {
                            AttributeName = "Fullname", AttributeType = "S"
                        },
                        new AttributeDefinition()
                        {
                            AttributeName = "DateTime", AttributeType = "S"
                        }
                    }
                };

                CreateTableResponse createTableResponse = _client.CreateTable(createTableRequest);

                while (createTableResponse.TableDescription.TableStatus != "ACTIVE")
                {
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
예제 #19
0
        public void TestDynamoSubsegmentNameIsCorrectForAWSSDKHandler()
        {
            var dynamo = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);

            CustomResponses.SetResponse(dynamo, null, null, true);
            AWSXRayRecorder.Instance.BeginSegment("test dynamo", TraceId);
#if NET45
            dynamo.ListTables();
#else
            dynamo.ListTablesAsync().Wait();
#endif
            var segment = TraceContext.GetEntity();
            AWSXRayRecorder.Instance.EndSegment();

            Assert.AreEqual("DynamoDBv2", segment.Subsegments[0].Name);
        }
        public void SingleSuccessfulRequest()
        {
            ThreadPool.QueueUserWorkItem(UDPListener);
            AmazonDynamoDBConfig config = new AmazonDynamoDBConfig
            {
                RegionEndpoint = Amazon.RegionEndpoint.USEast1
            };
            AmazonDynamoDBClient client = new AmazonDynamoDBClient(config);

            client.ListTables(new ListTablesRequest {
            });
            using (var udpClient = new UdpClient())
            {
                udpClient.Send(Encoding.UTF8.GetBytes("Exit"),
                               Encoding.UTF8.GetBytes("Exit").Length, "127.0.0.1", 31000);
                Thread.Sleep(10);
            }
            Assert.Equal(3, stash.Count);
            CSMTestUtilities testUtils = new CSMTestUtilities
            {
                Service        = "DynamoDB",
                ApiCall        = "ListTables",
                Domain         = "dynamodb.us-east-1.amazonaws.com",
                Region         = "us-east-1",
                HttpStatusCode = 200
            };

            foreach (var value in stash)
            {
                if (!value.Equals("Exit"))
                {
                    try
                    {
                        testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallEvent>(value));
                    }
                    catch (Exception e)
                    {
                        testUtils.Validate(JsonConvert.DeserializeObject <MonitoringAPICallAttempt>(value));
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #21
0
파일: FrmDynamoDB.cs 프로젝트: ramonfe/aws
        private void CreateTable()
        {
            var credentials = new BasicAWSCredentials(accessKey, secretKey);

            client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USWest1);

            var tableResponse = client.ListTables();

            if (!tableResponse.TableNames.Contains(tableName))
            {
                MessageBox.Show("Table not found, creating table => " + tableName);
                client.CreateTable(new CreateTableRequest
                {
                    TableName             = tableName,
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 3,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = hashKey,
                            KeyType       = KeyType.HASH
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition {
                            AttributeName = hashKey, AttributeType = ScalarAttributeType.S
                        }
                    }
                });

                bool isTableAvailable = false;
                while (!isTableAvailable)
                {
                    Console.WriteLine("Waiting for table to be active...");
                    Thread.Sleep(5000);
                    var tableStatus = client.DescribeTable(tableName);
                    isTableAvailable = tableStatus.Table.TableStatus == "ACTIVE";
                }
                MessageBox.Show("DynamoDB Table Created Successfully!");
            }
        }
예제 #22
0
        public void TestDynamoSubsegmentNameIsCorrect()
        {
            var dynamo = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1);

            new AWSSdkTracingHandler(AWSXRayRecorder.Instance).AddEventHandler(dynamo);
            CustomResponses.SetResponse(dynamo, null, null, true);

            AWSXRayRecorder.Instance.BeginSegment("test dynamo", TraceId);

            dynamo.ListTables();

            var segment = TraceContext.GetEntity();

            AWSXRayRecorder.Instance.EndSegment();

            Assert.AreEqual("DynamoDBv2", segment.Subsegments[0].Name);
        }
        private void CreateTable()
        {
            List <string> currentTables = _client.ListTables().TableNames;

            if (!currentTables.Contains(SchemaVersionTableName))
            {
                #region Form table creation

                var schema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = "ScriptName", KeyType = "HASH"
                    }
                };

                // The key attributes "FormId" is a string type and "InstanceId" is numeric type
                var definitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition {
                        AttributeName = "ScriptName", AttributeType = "S"
                    }
                };

                var throughput = new ProvisionedThroughput {
                    ReadCapacityUnits = 1, WriteCapacityUnits = 1
                };

                // Configure the CreateTable request
                var request = new CreateTableRequest
                {
                    TableName             = SchemaVersionTableName,
                    KeySchema             = schema,
                    ProvisionedThroughput = throughput,
                    AttributeDefinitions  = definitions
                };

                CreateTableResponse response = _client.CreateTable(request);
                string currentStatus         = response.TableDescription.TableStatus;
                WaitUntilTableReady(SchemaVersionTableName, currentStatus);

                #endregion
            }
        }
예제 #24
0
        public void ListMyTables()
        {
            Console.WriteLine("\n*** listing tables ***");
            string lastTableNameEvaluated = null;

            do
            {
                var request = new ListTablesRequest
                {
                    Limit = 2,
                    ExclusiveStartTableName = lastTableNameEvaluated
                };
                var response = client.ListTables(request);
                foreach (string name in response.TableNames)
                {
                    Console.WriteLine(name);
                }
                lastTableNameEvaluated = response.LastEvaluatedTableName;
            } while (lastTableNameEvaluated != null);
        }
예제 #25
0
        private static void ListAllTables()
        {
            // Initial value for the first page of table names.
            string lastEvaluatedTableName = null;

            do
            {
                // Create a request object to specify optional parameters.
                var request = new ListTablesRequest
                {
                    Limit = 10, // Page size.
                    ExclusiveStartTableName = lastEvaluatedTableName
                };

                var response = _dynamoDbClient.ListTables(request);
                var result   = response.TableNames;
                foreach (string name in result)
                {
                    Console.WriteLine(name);
                }

                lastEvaluatedTableName = response.LastEvaluatedTableName;
            } while (lastEvaluatedTableName != null);
        }
예제 #26
0
        /// <summary>
        /// Deletes all sample tables
        /// </summary>
        /// <param name="client"></param>
        public static void DeleteSampleTables(AmazonDynamoDBClient client)
        {
            foreach (var table in SAMPLE_TABLE_NAMES)
            {
                Console.WriteLine("Deleting table " + table);
                client.DeleteTable(new DeleteTableRequest {
                    TableName = table
                });
            }

            int remainingTables;

            do
            {
                Console.WriteLine("While sample tables still exist, sleeping for 5 seconds...");
                Thread.Sleep(TimeSpan.FromSeconds(5));

                Console.WriteLine("Getting list of tables");
                var currentTables = client.ListTables().TableNames;
                remainingTables = currentTables.Intersect(SAMPLE_TABLE_NAMES).Count();
            } while (remainingTables > 0);

            Console.WriteLine("Sample tables deleted");
        }
예제 #27
0
        public void TestAddEventHandlerToDynamoDBClient()
        {
            using (var client = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1))
            {
                _handler.AddEventHandler(client);
                string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
                CustomResponses.SetResponse(client, null, requestId, true);

                _recorder.BeginSegment("test", TraceId);

                client.ListTables();

                var segment    = TraceContext.GetEntity();
                var subsegment = segment.Subsegments[0];
                _recorder.EndSegment();

                Assert.AreEqual(segment.Subsegments.Count, 1);
                Assert.AreEqual(subsegment.Name, "DynamoDBv2");
                Assert.AreEqual(subsegment.Aws["region"], RegionEndpoint.USEast1.SystemName);
                Assert.AreEqual(subsegment.Aws["operation"], "ListTables");
                Assert.AreEqual(requestId, subsegment.Aws["request_id"]);
                Assert.AreEqual("aws", subsegment.Namespace);
            }
        }
        /// <summary>
        /// Uses the scan operator to retrieve all items in a table
        /// <remarks>[CAUTION] This operation can be very expensive if your table is large</remarks>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List <string> GetAllTables()
        {
            List <string> listTables = DynamoClient.ListTables().TableNames;

            return(listTables);
        }
예제 #29
0
        public void DataPlaneSamples()
        {
            {
                #region CreateTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define table schema:
                //  Table has a hash-key "Author" and a range-key "Title"
                List <KeySchemaElement> schema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Author", KeyType = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "Title", KeyType = "RANGE"
                    }
                };

                // Define key attributes:
                //  The key attributes "Author" and "Title" are string types
                List <AttributeDefinition> definitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Author", AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Title", AttributeType = "S"
                    }
                };

                // Define table throughput:
                //  Table has capacity of 20 reads and 50 writes
                ProvisionedThroughput throughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 20,
                    WriteCapacityUnits = 50
                };

                // Configure the CreateTable request
                CreateTableRequest request = new CreateTableRequest
                {
                    TableName             = "SampleTable",
                    KeySchema             = schema,
                    ProvisionedThroughput = throughput,
                    AttributeDefinitions  = definitions
                };

                // View new table properties
                TableDescription tableDescription = client.CreateTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Creation time: {0}", tableDescription.CreationDateTime);
                Console.WriteLine("Item count: {0}", tableDescription.ItemCount);
                Console.WriteLine("Table size (bytes): {0}", tableDescription.TableSizeBytes);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);

                // List table key schema
                List <KeySchemaElement> tableSchema = tableDescription.KeySchema;
                for (int i = 0; i < tableSchema.Count; i++)
                {
                    KeySchemaElement element = tableSchema[i];
                    Console.WriteLine("Key: Name = {0}, KeyType = {1}",
                                      element.AttributeName, element.KeyType);
                }

                // List attribute definitions
                List <AttributeDefinition> attributeDefinitions = tableDescription.AttributeDefinitions;
                for (int i = 0; i < attributeDefinitions.Count; i++)
                {
                    AttributeDefinition definition = attributeDefinitions[i];
                    Console.WriteLine("Attribute: Name = {0}, Type = {1}",
                                      definition.AttributeName, definition.AttributeType);
                }

                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            {
                #region DescribeTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Create DescribeTable request
                DescribeTableRequest request = new DescribeTableRequest
                {
                    TableName = "SampleTable"
                };

                // Issue DescribeTable request and retrieve the table description
                TableDescription tableDescription = client.DescribeTable(request).Table;

                // View new table properties
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Creation time: {0}", tableDescription.CreationDateTime);
                Console.WriteLine("Item count: {0}", tableDescription.ItemCount);
                Console.WriteLine("Table size (bytes): {0}", tableDescription.TableSizeBytes);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);
                // List table key schema
                List <KeySchemaElement> tableSchema = tableDescription.KeySchema;
                for (int i = 0; i < tableSchema.Count; i++)
                {
                    KeySchemaElement element = tableSchema[i];
                    Console.WriteLine("Key: Name = {0}, KeyType = {1}",
                                      element.AttributeName, element.KeyType);
                }

                // List attribute definitions
                List <AttributeDefinition> attributeDefinitions = tableDescription.AttributeDefinitions;
                for (int i = 0; i < attributeDefinitions.Count; i++)
                {
                    AttributeDefinition definition = attributeDefinitions[i];
                    Console.WriteLine("Attribute: Name = {0}, Type = {1}",
                                      definition.AttributeName, definition.AttributeType);
                }
                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            {
                #region ListTables Paging Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                string startTableName = null;
                do
                {
                    // Configure ListTables request with the marker value
                    ListTablesRequest request = new ListTablesRequest
                    {
                        ExclusiveStartTableName = startTableName,
                    };

                    // Issue call
                    ListTablesResult result = client.ListTables(request);

                    // List retrieved tables
                    List <string> tables = result.TableNames;
                    Console.WriteLine("Retrieved tables: {0}",
                                      string.Join(", ", tables));

                    // Update marker value from the result
                    startTableName = result.LastEvaluatedTableName;
                } while (!string.IsNullOrEmpty(startTableName)); // Test marker value

                #endregion
            }

            {
                #region ListTables NonPaging Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Issue call
                ListTablesResult result = client.ListTables();

                // List retrieved tables
                List <string> tables = result.TableNames;
                Console.WriteLine("Retrieved tables: {0}",
                                  string.Join(", ", tables));

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region UpdateTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define new table throughput:
                //  Table will now have capacity of 40 reads and 50 writes
                ProvisionedThroughput throughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 40,
                    WriteCapacityUnits = 50
                };

                // Compose the UpdateTable request
                UpdateTableRequest request = new UpdateTableRequest
                {
                    TableName             = "SampleTable",
                    ProvisionedThroughput = throughput
                };

                // View new table properties
                TableDescription tableDescription = client.UpdateTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region DeleteTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Configure the DeleteTable request
                DeleteTableRequest request = new DeleteTableRequest
                {
                    TableName = "SampleTable"
                };

                // Issue DeleteTable request and retrieve the table description
                TableDescription tableDescription = client.DeleteTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);

                #endregion
            }
        }
예제 #30
0
        /// <summary>
        /// Creates all samples defined in SampleTables map
        /// </summary>
        /// <param name="client"></param>
        public static void CreateSampleTables(AmazonDynamoDBClient client)
        {
            Console.WriteLine("Getting list of tables");
            List <string> currentTables = client.ListTables().TableNames;

            Console.WriteLine("Number of tables: " + currentTables.Count);

            bool tablesAdded = false;

            if (!currentTables.Contains("Actors"))
            {
                Console.WriteLine("Table Actors does not exist, creating");
                client.CreateTable(new CreateTableRequest
                {
                    TableName             = "Actors",
                    ProvisionedThroughput = new ProvisionedThroughput {
                        ReadCapacityUnits = 3, WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Name",
                            KeyType       = KeyType.HASH
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition {
                            AttributeName = "Name", AttributeType = ScalarAttributeType.S
                        }
                    }
                });
                tablesAdded = true;
            }

            if (!currentTables.Contains("Movies"))
            {
                Console.WriteLine("Table Movies does not exist, creating");
                client.CreateTable(new CreateTableRequest
                {
                    TableName             = "Movies",
                    ProvisionedThroughput = new ProvisionedThroughput {
                        ReadCapacityUnits = 3, WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Title",
                            KeyType       = KeyType.HASH
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "Released",
                            KeyType       = KeyType.RANGE
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition {
                            AttributeName = "Title", AttributeType = ScalarAttributeType.S
                        },
                        new AttributeDefinition {
                            AttributeName = "Released", AttributeType = ScalarAttributeType.S
                        }
                    }
                });
                tablesAdded = true;
            }

            if (tablesAdded)
            {
                bool allActive;
                do
                {
                    allActive = true;
                    Console.WriteLine("While tables are still being created, sleeping for 5 seconds...");
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    foreach (var tableName in SAMPLE_TABLE_NAMES)
                    {
                        TableStatus tableStatus = GetTableStatus(client, tableName);
                        if (!object.Equals(tableStatus, TableStatus.ACTIVE))
                        {
                            allActive = false;
                        }
                    }
                } while (!allActive);
            }

            Console.WriteLine("All sample tables created");
        }