예제 #1
0
        private async Task CreateTableProductCatalog()
        {
            string tableName = "ProductCatalog";

            var response = await _client.CreateTableAsync(new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "N"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = "HASH"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5
                }
            });

            await TableTools.WaitTillTableCreated(_client, tableName, response);
        }
예제 #2
0
        //private static async Task<TableDescription> BuildOrDescribeTable()
        private static TableDescription BuildOrDescribeTable()
        {
            // Define the cancellation token.
            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;

            // build the widget table
            var request = new CreateTableRequest(
                tableName: "Widgets",
                keySchema: new List <KeySchemaElement>
            {
                new KeySchemaElement
                {
                    AttributeName = "WidgetId",
                    KeyType       = KeyType.HASH
                }
            },
                attributeDefinitions: new List <AttributeDefinition>
            {
                new AttributeDefinition()
                {
                    AttributeName = "WidgetId",
                    AttributeType = ScalarAttributeType.S
                }
            },
                provisionedThroughput: new ProvisionedThroughput
            {
                ReadCapacityUnits  = 1,
                WriteCapacityUnits = 1
            }
                );

            Console.WriteLine("Sending request to build Widgets table...");
            try
            {
                //var result = await dynamoclient.CreateTableAsync(request);
                var result = dynamoclient.CreateTableAsync(request).Result;
                Console.WriteLine("Table created.");
                return(result.TableDescription);
            }
            //catch (ResourceInUseException)
            catch (Exception e)
            {
                if (e.Message.Contains("Table already exists"))
                {
                    // Table already created, just describe it
                    Console.WriteLine("Table already exists. Fetching description...");
                }
                return /*await*/
                       (dynamoclient.DescribeTableAsync(new DescribeTableRequest("Widgets"), token).Result.Table);
            }
        }
예제 #3
0
        /// <summary>
        /// CreateTableAsync will check to see if a given table exists and if not it will create a Table in DynamoDB
        /// <remarks>[CAUTION] This operation will return null if the table exists</remarks>
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="readCapacityUnits"></param>
        /// <param name="writeCapacityUnits"></param>
        /// <param name="hashKeySchemaElement"></param>
        /// <param name="rangeKeySchemaElement"></param>
        /// <param name="hashAttributeDefinition"></param>
        /// <param name="rangeAttributeDefinition"></param>
        /// <returns>A Task of type CreateTableResponse</returns>
        public virtual async Task <CreateTableResponse> CreateTableAsync(TableDefinition tableDefinition)
        {
            if (!(await DoesTableExists(tableDefinition.TableName)))
            {
                var createTableRequest = new CreateTableRequest
                {
                    TableName             = tableDefinition.TableName,
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = tableDefinition.ReadCapacityUnits,
                        WriteCapacityUnits = tableDefinition.WriteCapacityUnits
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        tableDefinition.HashKeySchemaElement,
                        tableDefinition.RangeKeySchemaElement ?? null
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        tableDefinition.HashAttributeDefinition,
                        tableDefinition.RangeAttributeDefinition ?? null
                    }
                };

                return(await _client.CreateTableAsync(createTableRequest).ConfigureAwait(false));
            }

            return(null);
        }
예제 #4
0
        //public async Task GetStuffFromDynamoAsync()
        //{
        //    var someTestDocument = new User()
        //    {
        //        id = "someAwesomeUser",
        //        name = "Tom2"
        //    };

        //    log("Saving document...");
        //    await dbContext.SaveAsync(someTestDocument);
        //    log("Finishes saving document...");

        //    log("Retrieving document...");
        //    List<ScanCondition> conditions = new List<ScanCondition>();
        //    conditions.Add(new ScanCondition("id", ScanOperator.Equal, someTestDocument.id));
        //    var allDocs = await dbContext.ScanAsync<User>(conditions).GetRemainingAsync();
        //    var savedState = allDocs.FirstOrDefault();
        //    log("Finished retrieving document...");

        //    LambdaLogger.Log($"retrieved record has name: {savedState.name}");
        //}

        private async Task EnsureTableExists(AmazonDynamoDBClient client, string tableName)
        {
            var tableResponse = client.ListTablesAsync().Result;

            if (!tableResponse.TableNames.Contains(tableName))
            {
                log($"List of tables did not contains {tableName}... going to create it");

                await client.CreateTableAsync(
                    new CreateTableRequest
                {
                    TableName = tableName,
                    KeySchema = new List <KeySchemaElement> {
                        new KeySchemaElement("id", KeyType.HASH)
                    },
                    AttributeDefinitions = new List <AttributeDefinition> {
                        new AttributeDefinition("id", ScalarAttributeType.S)
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 3,
                        WriteCapacityUnits = 1
                    }
                });
            }
        }
        private async Task CreateTable()
        {
            var createRequest = new CreateTableRequest(_tableName, new List <KeySchemaElement>()
            {
                new KeySchemaElement("id", KeyType.HASH)
            })
            {
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition("id", ScalarAttributeType.S)
                },
                BillingMode = BillingMode.PAY_PER_REQUEST
            };

            var createResponse = await _client.CreateTableAsync(createRequest);

            int  i       = 0;
            bool created = false;

            while ((i < 10) && (!created))
            {
                try
                {
                    await Task.Delay(1000);

                    var poll = await _client.DescribeTableAsync(_tableName);

                    created = (poll.Table.TableStatus == TableStatus.ACTIVE);
                    i++;
                }
                catch (ResourceNotFoundException)
                {
                }
            }
        }
예제 #6
0
            private async Task CreateDynamoTable(string tableName)
            {
                AmazonDynamoDBConfig ddbConfig = new AmazonDynamoDBConfig
                {
                    ServiceURL = "http://localhost:8000"
                };
                var client = new AmazonDynamoDBClient(ddbConfig);

                try
                {
                    await client.DeleteTableAsync(tableName);
                }
                catch
                {
                }

                await client.CreateTableAsync(new CreateTableRequest()
                {
                    TableName = tableName,
                    KeySchema = new List <KeySchemaElement>()
                    {
                        new KeySchemaElement("HashKey", KeyType.HASH),
                        new KeySchemaElement("SortKey", KeyType.RANGE)
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition("HashKey", ScalarAttributeType.S),
                        new AttributeDefinition("SortKey", ScalarAttributeType.N)
                    },
                    ProvisionedThroughput = new ProvisionedThroughput(100, 100)
                });
            }
예제 #7
0
        public async ValueTask <CreateTableResponse> CreateTable(string tableName)
        {
            var response = await _client.CreateTableAsync(new CreateTableRequest()
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = OrderIdKey,
                        AttributeType = AttributeTypeS
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = OrderIdKey,
                        KeyType       = "HASH" //Partition key
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5
                }
            });

            return(response);
        }
        public async Task <CreateTableResponse> CreateTable(string tableName, List <KeySchemaElement> keySchema, List <AttributeDefinition> attributes, long readCapacityUnits = 5, long writeCapacityUnits = 5, bool streamEnabled = true, StreamViewType streamViewType = default)
        {
            try
            {
                var request = new CreateTableRequest
                {
                    TableName             = tableName,
                    KeySchema             = keySchema,
                    AttributeDefinitions  = attributes,
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = readCapacityUnits,
                        WriteCapacityUnits = writeCapacityUnits
                    },
                    StreamSpecification = new StreamSpecification
                    {
                        StreamEnabled  = streamEnabled,
                        StreamViewType = streamViewType ?? StreamViewType.NEW_AND_OLD_IMAGES
                    }
                };

                return(await AmazonDynamoDBClient.CreateTableAsync(request).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                LogDynamoException(ref ex);
                throw;
            }
        }
예제 #9
0
        private async Task EnsureProvisionedAsync(CancellationToken token)
        {
            try
            {
                await _client.DescribeTableAsync(TableName, token);
            }
            catch (ResourceNotFoundException)
            {
                // TODO: Log

                // Default table information for the Ubisoft key table
                var table = new CreateTableRequest(
                    TableName,
                    new List <KeySchemaElement> {
                    new KeySchemaElement("id", KeyType.HASH)
                },
                    new List <AttributeDefinition> {
                    new AttributeDefinition("id", ScalarAttributeType.S)
                },
                    new ProvisionedThroughput(5, 5)
                    );
                await _client.CreateTableAsync(table, token);

                // Wait for the table to finish being created
                await Task.Delay(5000, token);
            }
        }
예제 #10
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);
        }
예제 #11
0
        private async Task <HttpStatusCode> createRewardTable()
        {
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();

            var request = new CreateTableRequest
            {
                TableName            = "Rewards",
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = "HASH" //Partition key
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 2,
                    WriteCapacityUnits = 1
                }
            };

            var response = await client.CreateTableAsync(request);

            Debug.WriteLine("HTTP Status Code: " + response.HttpStatusCode.ToString());
            return(response.HttpStatusCode);
        }
        private HttpStatusCode CreateTable(string tableName)
        {
            var networkTableRequest = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "MasterId",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "MasterId",
                        KeyType       = "HASH"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 5,
                    WriteCapacityUnits = 5
                }
            };

            var createResponse = _client.CreateTableAsync(networkTableRequest).Result;

            return(createResponse.HttpStatusCode);
        }
예제 #13
0
 private static async Task CreateTable()
 {
     await client.CreateTableAsync(new CreateTableRequest
     {
         TableName            = tableName,
         AttributeDefinitions = new List <AttributeDefinition>
         {
             new AttributeDefinition
             {
                 AttributeName = "Id",
                 AttributeType = "S"
             }
         },
         KeySchema = new List <KeySchemaElement>
         {
             new KeySchemaElement
             {
                 AttributeName = "Id",
                 KeyType       = "HASH"
             }
         },
         ProvisionedThroughput = new ProvisionedThroughput
         {
             ReadCapacityUnits  = 5,
             WriteCapacityUnits = 5
         }
     });
 }
예제 #14
0
        private static void CreateStationTable()
        {
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();
            string tableName            = "ProductCatalog";

            var request = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "uid",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "uid",
                        KeyType       = "HASH" //Partition key
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5
                }
            };

            var response = client.CreateTableAsync(request);
        }
예제 #15
0
        public static void CreateLockTableInDynamoDB(AmazonDynamoDBClient client, string lockTableName,
                                                     ProvisionedThroughput provisionedThroughput, string partitionKeyName)
        {
            KeySchemaElement        partitionKeyElement = new KeySchemaElement(partitionKeyName, KeyType.HASH);
            List <KeySchemaElement> keySchema           = new List <KeySchemaElement> {
                partitionKeyElement
            };

            List <AttributeDefinition> attributeDefinitions =
                new List <AttributeDefinition> {
                new AttributeDefinition(partitionKeyName, ScalarAttributeType.S)
            };

            //if (!string.IsNullOrEmpty(sortKeyName))
            //{
            //    KeySchemaElement sortKeyElement = new KeySchemaElement(sortKeyName, KeyType.RANGE);
            //    keySchema.Add(sortKeyElement);

            //    attributeDefinitions.Add(new AttributeDefinition(sortKeyName, ScalarAttributeType.S));
            //}

            CreateTableRequest createTableRequest =
                new CreateTableRequest(lockTableName, keySchema, attributeDefinitions, provisionedThroughput);

            var createTableResponse = client.CreateTableAsync(createTableRequest).Result;

            if (createTableResponse.HttpStatusCode != HttpStatusCode.OK)
            {
                //todo: fill this out with identifying information for the error
                throw new LockTableCreationFailedException("failed");
            }
        }
예제 #16
0
        private async Task CreateTable()
        {
            await client.CreateTableAsync(
                TABLE_NAME,
                keySchema : new List <KeySchemaElement>
            {
                new KeySchemaElement
                {
                    AttributeName = "Id",
                    KeyType       = KeyType.HASH
                }
            },
                attributeDefinitions : new List <AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "Id",
                    AttributeType = ScalarAttributeType.S
                }
            },
                provisionedThroughput : new ProvisionedThroughput(1, 1)
                );

            await WaitForActiveTable();
        }
        public void RunBeforeAnyTests()
        {
            var clientConfig = new AmazonDynamoDBConfig {
                ServiceURL = "http://dynamodb-database:8000"
            };

            DynamoDBClient = new AmazonDynamoDBClient(clientConfig);
            try
            {
                var request = new CreateTableRequest("APIAuthenticatorData",
                                                     new List <KeySchemaElement> {
                    new KeySchemaElement("apiName", KeyType.HASH), new KeySchemaElement("environment", KeyType.RANGE)
                },
                                                     new List <AttributeDefinition> {
                    new AttributeDefinition("apiName", ScalarAttributeType.S), new AttributeDefinition("environment", ScalarAttributeType.S)
                },
                                                     new ProvisionedThroughput(3, 3));

                DynamoDBClient.CreateTableAsync(request).GetAwaiter().GetResult();
            }
            catch (ResourceInUseException)
            {
            }

            DynamoDbContext = new DynamoDBContext(DynamoDBClient);
        }
예제 #18
0
        /// <summary>
        /// Method to create table in Dynamo DB
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns>RequestId is not empty it means table is created or table doesnot exists</returns>
        public string FuncCreateTableDynamoDBAsync(string tableName)
        {
            string requestId = string.Empty;

            try
            {
                System.Threading.Tasks.Task <ListTablesResponse> currentTablesAsync = client.ListTablesAsync();
                List <string> lstTableNames = currentTablesAsync.Result.TableNames;
                if (!lstTableNames.Contains(tableName))
                {
                    CreateTableRequest request = new CreateTableRequest
                    {
                        TableName            = "TBL_SPLITWISEBOTCONFIGVALUES",
                        AttributeDefinitions = new List <AttributeDefinition>
                        {
                            new AttributeDefinition
                            {
                                AttributeName = "KEY",
                                // "S" = string, "N" = number, and so on.
                                AttributeType = "S"
                            },
                            new AttributeDefinition
                            {
                                AttributeName = "TYPE",
                                AttributeType = "S"
                            }
                        },
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement
                            {
                                AttributeName = "KEY",
                                // "HASH" = hash key, "RANGE" = range key.
                                KeyType = "HASH"
                            },
                            new KeySchemaElement
                            {
                                AttributeName = "TYPE",
                                KeyType       = "RANGE"
                            },
                        },
                        ProvisionedThroughput = new ProvisionedThroughput
                        {
                            ReadCapacityUnits  = 10,
                            WriteCapacityUnits = 5
                        },
                    };

                    System.Threading.Tasks.Task <CreateTableResponse> response = client.CreateTableAsync(request);

                    requestId = response.Result.ResponseMetadata.RequestId.ToString();
                }
                return(requestId);
            }
            catch (Exception)
            {
                return(requestId);
            }
        }
예제 #19
0
        internal Task <CreateTableResponse> CreateTableAsync(string tableName, IEnumerable <AttributeDefinition> attributes,
                                                             IEnumerable <KeySchemaElement> schema, ProvisionedThroughput thruPut, AmazonDynamoDBClient client)
        {
            var createRequest  = GetCreateTableRequest(tableName, attributes, schema, thruPut);
            var createResponse = client.CreateTableAsync(createRequest);

            return(createResponse);
        }
        private async Task CreateTable()
        {
            var currentTables = await client.ListTablesAsync();

            if (!currentTables.TableNames.Contains("Book"))
            {
                var request = new CreateTableRequest
                {
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "Author",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Id",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "Author",
                            KeyType       = "Range"
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 15,
                        WriteCapacityUnits = 15
                    },
                    TableName = "Book"
                };

                await client.CreateTableAsync(request);

                var status = TableStatus.CREATING;

                do
                {
                    var response = await client.DescribeTableAsync(new DescribeTableRequest
                    {
                        TableName = "Book"
                    });

                    status = response.Table.TableStatus;
                } while (status != TableStatus.ACTIVE);
            }
        }
예제 #21
0
        public async Task ResetTable()
        {
            try
            {
                var tables = await _client.ListTablesAsync();

                // Delete the table
                if (tables.TableNames.Contains(_tablename))
                {
                    var respDelete = await _client.DeleteTableAsync(_tablename);

                    if (respDelete.HttpStatusCode == HttpStatusCode.OK)
                    {
                        System.Threading.Thread.Sleep(10000); // Give AWS some time to actually delete the table
                    }
                    else
                    {
                        throw new Exception($"Could not delete table {_tablename}. Status code: {respDelete.HttpStatusCode}");
                    }
                }

                // Create the table
                var request = new CreateTableRequest
                {
                    TableName = _tablename,
                    KeySchema = new List <KeySchemaElement>()
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Id",
                            KeyType       = KeyType.HASH
                        }
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = ScalarAttributeType.N
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = _readCapacity,
                        WriteCapacityUnits = _writeCapacity
                    }
                };

                var respCreate = await _client.CreateTableAsync(request);

                System.Threading.Thread.Sleep(10000); // Give AWS some time to actually create the table
            }
            catch (Exception e)
            {
                Console.WriteLine($"  {DateTime.Now}: ERROR! {e.Message}");
            }
        }
예제 #22
0
        private static async Task <IList <Result> > RunBenchmarks()
        {
            var config = new AmazonDynamoDBConfig
            {
                ServiceURL = "http://localhost:8000/"
            };
            var client = new AmazonDynamoDBClient(config);

            var results = new List <Result>();

            #region Make sure testing table exists

            var tables = await client.ListTablesAsync();

            if (!tables.TableNames.Contains("Benchmarking"))
            {
                await client.CreateTableAsync("Benchmarking", new List <KeySchemaElement> {
                    new KeySchemaElement("Id", KeyType.HASH)
                }, new List <AttributeDefinition> {
                    new AttributeDefinition("Id", ScalarAttributeType.N)
                }, new ProvisionedThroughput(1, 1));
            }

            #endregion Make sure testing table exists

            IBenchmark[] benchmarks = new IBenchmark[] {
                new AwsSdkBenchmark(client),
                new RepositoryBenchmark(client)
            };

            var iterations = new[] { 10, 100, 1000 };

            foreach (var benchmark in benchmarks)
            {
                foreach (var iteration in iterations)
                {
                    Console.WriteLine($"Set {iteration}");
                    results.Add(await benchmark.AddItems(iteration));
                    results.Add(await benchmark.GetItemsSimple(iteration));
                    results.Add(await benchmark.GetItemsComplex(iteration));
                    results.Add(await benchmark.UpdateItems(iteration));
                    results.Add(await benchmark.ListItemsSimple(iteration));
                    results.Add(await benchmark.ListItemsComplex(iteration));
                    results.Add(await benchmark.DeleteItemsSimple(iteration));
                    results.Add(await benchmark.AddItems(iteration));
                    results.Add(await benchmark.DeleteItemsComplex(iteration));
                }
            }

            #region Delete testing table

            await client.DeleteTableAsync("Benchmarking");

            #endregion Delete testing table

            return(results);
        }
예제 #23
0
    private static void CreateExampleTable(AmazonDynamoDBClient client,
                                           string tableName,
                                           CancellationToken cancel)
    {
        Console.WriteLine("\n*** Creating table ***");
        var request = new CreateTableRequest
        {
            AttributeDefinitions = new List <AttributeDefinition>()
            {
                new AttributeDefinition
                {
                    AttributeName = "Id",
                    AttributeType = "N"
                },
                new AttributeDefinition
                {
                    AttributeName = "ReplyDateTime",
                    AttributeType = "N"
                }
            },
            KeySchema = new List <KeySchemaElement>
            {
                new KeySchemaElement
                {
                    AttributeName = "Id",
                    KeyType       = "HASH" //Partition key
                },
                new KeySchemaElement
                {
                    AttributeName = "ReplyDateTime",
                    KeyType       = "RANGE" //Sort key
                }
            },
            ProvisionedThroughput = new ProvisionedThroughput
            {
                ReadCapacityUnits  = 5,
                WriteCapacityUnits = 6
            },
            TableName = tableName
        };

        var response = client.CreateTableAsync(request, cancel).Result;

        var tableDescription = response.TableDescription;

        Console.WriteLine("{1}: {0} \t ReadsPerSec: {2} \t WritesPerSec: {3}",
                          tableDescription.TableStatus,
                          tableDescription.TableName,
                          tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                          tableDescription.ProvisionedThroughput.WriteCapacityUnits);

        string status = tableDescription.TableStatus;

        Console.WriteLine(tableName + " - " + status);

        WaitUntilTableReady(client, tableName, cancel);
    }
예제 #24
0
        private async Task EnsureTables()
        {
            foreach (var tcr in _tableCreateReqs)
            {
                var response = await _client.CreateTableAsync(tcr);

                await TableTools.WaitTillTableCreated(_client, tcr.TableName, response);
            }
        }
예제 #25
0
        private async static Task CreateOldMoviesTableAsync()
        {
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();

            string tableToCreate = MovieTableName;

            var  tables     = client.ListTablesAsync();
            var  tableNames = tables.Result.TableNames;
            bool tableFound = false;

            foreach (string tableName in tableNames)
            {
                if (tableName == tableToCreate)
                {
                    tableFound = true;
                    break;
                }
            }
            if (tableFound)
            {
                Console.WriteLine("Could not create table.  Table " + tableToCreate + " already exists");
                return;
            }

            // Create the table

            var request = new CreateTableRequest
            {
                TableName            = MovieTableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "MovieName",
                        AttributeType = "S",
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "MovieName",
                        KeyType       = "HASH"                    // Partition key
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5
                }
            };

            await client.CreateTableAsync(request);

            Console.WriteLine("Table " + MovieTableName + " created");
        }
예제 #26
0
        public async Task CreateTable(string tableName)
        {
            Console.WriteLine("\n*** Creating table ***");
            var request = new CreateTableRequest
            {
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "N"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "CreatedDateTime",
                        AttributeType = "N"
                    }
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = "HASH" //Partition key
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "CreatedDateTime",
                        KeyType       = "RANGE" //Sort key
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 5,
                    WriteCapacityUnits = 6
                },
                TableName = tableName
            };

            var response = await client.CreateTableAsync(request);

            var tableDescription = response.TableDescription;

            Console.WriteLine("{1}: {0} \t ReadsPerSec: {2} \t WritesPerSec: {3}",
                              tableDescription.TableStatus,
                              tableDescription.TableName,
                              tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                              tableDescription.ProvisionedThroughput.WriteCapacityUnits);

            string status = tableDescription.TableStatus;

            Console.WriteLine(tableName + " - " + status);

            await WaitUntilTableReady(tableName);
        }
예제 #27
0
        static void Main(string[] args)
        {
            var config = new AmazonDynamoDBConfig {
                ServiceURL           = "http://localhost:4569",
                UseHttp              = true,
                AuthenticationRegion = "us-east-1"
            };

            var client = new AmazonDynamoDBClient(config);

            var currentTables = client.ListTablesAsync().Result.TableNames;

            Console.WriteLine("Number of tables: " + currentTables.Count);
            if (!currentTables.Contains(tableName))
            {
                var createTableRequest = new CreateTableRequest {
                    TableName            = tableName,
                    AttributeDefinitions = new List <AttributeDefinition> {
                        new AttributeDefinition {
                            AttributeName = "Id",
                            // "S" = string, "N" = number, etc.
                            AttributeType = "N"
                        },
                        new AttributeDefinition {
                            AttributeName = "Type",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement> {
                        new KeySchemaElement {
                            AttributeName = "Id",
                            // "HASH" = hash key, "RANGE" = range key.
                            KeyType = "HASH"
                        },
                        new KeySchemaElement {
                            AttributeName = "Type",
                            KeyType       = "RANGE"
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput {
                        ReadCapacityUnits  = 10,
                        WriteCapacityUnits = 5
                    }
                };

                var response = client.CreateTableAsync(createTableRequest).Result;
                Console.WriteLine("Table created with request ID: " +
                                  response.ResponseMetadata.RequestId);
            }
            else
            {
                Console.WriteLine($"Table with name: {tableName} already exists");
            }
        }
        private async Task CreateDynamoDbTableAsync(string tableName)
        {
            var response = new CreateTableResponse();

            try
            {
                var request = new CreateTableRequest
                {
                    TableName            = tableName,
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "Version",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement {
                            AttributeName = "Id", KeyType = KeyType.HASH
                        },
                        new KeySchemaElement {
                            AttributeName = "Version", KeyType = KeyType.RANGE
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 5,
                        WriteCapacityUnits = 5
                    },
                    StreamSpecification = new StreamSpecification
                    {
                        StreamViewType = StreamViewType.NEW_IMAGE,
                        StreamEnabled  = true
                    }
                };

                var createTableResponse = _dynamoDbClient.CreateTableAsync(request);
                response = await createTableResponse;
            }
            catch (Exception ex)
            {
                Logger.Log($"ERROR: Failed to create the new table, because: {ex.Message}");
            }

            await WaitTillTableCreatedAsync(tableName, response);
        }
예제 #29
0
        private async Task <CreateTableResponse> CreateTableAsync(string tableName)
        {
            var createTableReq = new CreateTableRequest
            {
                TableName = tableName,
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = "PK", KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = "SK", KeyType = KeyType.RANGE
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition> {
                    new AttributeDefinition {
                        AttributeName = "PK", AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition {
                        AttributeName = "SK", AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition {
                        AttributeName = "GSI1", AttributeType = ScalarAttributeType.S
                    }
                },
                ProvisionedThroughput  = new ProvisionedThroughput(5, 5),
                GlobalSecondaryIndexes = new List <GlobalSecondaryIndex>
                {
                    new GlobalSecondaryIndex
                    {
                        IndexName = "GSI1",
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement {
                                AttributeName = "GSI1", KeyType = KeyType.HASH
                            },
                            new KeySchemaElement {
                                AttributeName = "SK", KeyType = KeyType.RANGE
                            }
                        },
                        Projection = new Projection
                        {
                            ProjectionType = ProjectionType.ALL
                        },
                        ProvisionedThroughput = new ProvisionedThroughput(5, 5)
                    }
                }
            };

            return(await _dynamoDbClient.CreateTableAsync(createTableReq));
        }
예제 #30
0
        private static async Task CreateTable(AmazonDynamoDBClient client, string tableName)
        {
            CreateTableRequest request = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Type",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "Type",
                        KeyType       = "RANGE"
                    },
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 1,
                    WriteCapacityUnits = 2
                },
            };

            await client.CreateTableAsync(request);

            await Policy
            .HandleResult <DescribeTableResponse>(resp =>
            {
                Console.WriteLine("Waiting for table to become active.");
                return(resp.Table.TableStatus != "ACTIVE");
            })
            .WaitAndRetryAsync(12, i => TimeSpan.FromMilliseconds(20 * Math.Pow(2, i)).AddJitter(400, 900))
            .ExecuteAsync(async() => await client.DescribeTableAsync(tableName));

            Console.WriteLine($"Table {tableName} was created.");
        }