コード例 #1
0
        public static async Task <bool> CreateTable_async(string tableName,
                                                          List <AttributeDefinition> tableAttributes,
                                                          List <KeySchemaElement> tableKeySchema,
                                                          ProvisionedThroughput provisionedThroughput)
        {
            bool response = true;

            // Build the 'CreateTableRequest' structure for the new table
            var request = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = tableAttributes,
                KeySchema            = tableKeySchema,
                // Provisioned-throughput settings are always required,
                // although the local test version of DynamoDB ignores them.
                ProvisionedThroughput = provisionedThroughput
            };

            try
            {
                var makeTbl = await DdbIntro.Client.CreateTableAsync(request);
            }
            catch (Exception)
            {
                response = false;
            }

            return(response);
        }
コード例 #2
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");
            }
        }
コード例 #3
0
        public static async Task CreatingTable_async(string newTableName,
                                                     List <AttributeDefinition> tableAttributes,
                                                     List <KeySchemaElement> tableKeySchema,
                                                     ProvisionedThroughput provisionedThroughput)
        {
            Console.WriteLine("  -- Creating a new table named {0}...", newTableName);

            if (await checkingTableExistence_async(newTableName))
            {
                Console.WriteLine("     -- No need to create a new table...");
                return;
            }

            if (OperationFailed)
            {
                return;
            }

            OperationSucceeded = false;
            Task <bool> newTbl = CreateNewTable_async(newTableName,
                                                      tableAttributes,
                                                      tableKeySchema,
                                                      provisionedThroughput);
            await newTbl;
        }
コード例 #4
0
        /*--------------------------------------------------------------------------
         *                CreateNewTable
         *--------------------------------------------------------------------------*/
        public bool CreateNewTable(string tableName,
                                   List <AttributeDefinition> tableAttributes,
                                   List <KeySchemaElement> tableKeySchema,
                                   ProvisionedThroughput provisionedThroughput)
        {
            // Build the 'CreateTableRequest' structure for the new table
            var request = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = tableAttributes,
                KeySchema            = tableKeySchema,
                // Provisioned-throughput settings are always required,
                // although the local test version of DynamoDB ignores them.
                ProvisionedThroughput = provisionedThroughput
            };


            try
            {
                DynamoClient.CreateTable(request);
                //Created the {tableName} table successfully!
            }
            catch
            {
                // FAILED to create the new table, because: {0}.", ex.Message);

                throw new Exception("Failed creating collection. Please try after a while");
            }

            return(true);
        }
コード例 #5
0
ファイル: DynamoDBStorage.cs プロジェクト: LiveFly/orleans
 /// <summary>
 /// Create a DynamoDBStorage instance
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="accessKey"></param>
 /// <param name="secretKey"></param>
 /// <param name="token"></param>
 /// <param name="profileName"></param>
 /// <param name="service"></param>
 /// <param name="readCapacityUnits"></param>
 /// <param name="writeCapacityUnits"></param>
 /// <param name="useProvisionedThroughput"></param>
 /// <param name="createIfNotExists"></param>
 /// <param name="updateIfExists"></param>
 public DynamoDBStorage(
     ILogger logger,
     string service,
     string accessKey              = "",
     string secretKey              = "",
     string token                  = "",
     string profileName            = "",
     int readCapacityUnits         = DefaultReadCapacityUnits,
     int writeCapacityUnits        = DefaultWriteCapacityUnits,
     bool useProvisionedThroughput = true,
     bool createIfNotExists        = true,
     bool updateIfExists           = true)
 {
     if (service == null)
     {
         throw new ArgumentNullException(nameof(service));
     }
     this.accessKey   = accessKey;
     this.secretKey   = secretKey;
     this.token       = token;
     this.profileName = profileName;
     this.service     = service;
     this.useProvisionedThroughput = useProvisionedThroughput;
     this.provisionedThroughput    = this.useProvisionedThroughput
         ? new ProvisionedThroughput(readCapacityUnits, writeCapacityUnits)
         : null;
     this.createIfNotExists = createIfNotExists;
     this.updateIfExists    = updateIfExists;
     Logger = logger;
     CreateClient();
 }
コード例 #6
0
        public async Task Initialize(bool createTables = false, ProvisionedThroughput provisionedThroughput = null, StreamSpecification streamSpecification = null)
        {
            if (createTables)
            {
                Table table = _dynamoDBContext.GetTargetTable <TReadModel>();

                var createTableRequest = new CreateTableRequest()
                {
                    ProvisionedThroughput = provisionedThroughput,
                    TableName             = table.TableName,
                    LocalSecondaryIndexes = table.LocalSecondaryIndexes
                                            .Select(kv => new LocalSecondaryIndex()
                    {
                        KeySchema  = kv.Value.KeySchema,
                        IndexName  = kv.Value.IndexName,
                        Projection = kv.Value.Projection
                    }).ToList(),
                    GlobalSecondaryIndexes = table.GlobalSecondaryIndexes.Select(kv => new GlobalSecondaryIndex()
                    {
                        KeySchema             = kv.Value.KeySchema,
                        Projection            = kv.Value.Projection,
                        IndexName             = kv.Value.IndexName,
                        ProvisionedThroughput = new ProvisionedThroughput(kv.Value.ProvisionedThroughput.ReadCapacityUnits, kv.Value.ProvisionedThroughput.WriteCapacityUnits)
                    }).ToList(),
                    AttributeDefinitions = table.Attributes,
                    StreamSpecification  = streamSpecification,
                    KeySchema            = table.Keys.Select(kv => new KeySchemaElement(kv.Key, kv.Value.IsHash ? KeyType.HASH : KeyType.RANGE)).ToList()
                };

                await _dynamoDBClient.CreateTableAsync(createTableRequest).ConfigureAwait(false);
            }
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IndexProvision"/> class.
 /// </summary>
 /// <param name="indexName">The name of the global secondary index.</param>
 /// <param name="throughput">The provisioned throughput if the global secondary index.</param>
 public IndexProvision(string indexName, ProvisionedThroughput throughput)
 {
     DynamoValidator.ThrowIfIndexNameIsNotValid(indexName);
     Validator.ThrowIfNull(throughput, nameof(throughput));
     IndexName  = indexName;
     Throughput = throughput;
 }
コード例 #8
0
        public Task CreateTableAsync(
            string tableName,
            IReadOnlyList <KeySchemaElement> keySchema,
            IReadOnlyList <AttributeDefinition> attributes,
            ProvisionedThroughput provisionedThroughput)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("Table name is required.", nameof(tableName));
            }

            return(createTableAsync());

            async Task createTableAsync()
            {
                if (!await IsExistingTableAsync(tableName))
                {
                    var request = new CreateTableRequest
                    {
                        TableName             = tableName,
                        AttributeDefinitions  = attributes.ToList(),
                        KeySchema             = keySchema.ToList(),
                        ProvisionedThroughput = provisionedThroughput
                    };

                    await _dynamoDb.CreateTableAsync(request);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Creates a table in dynamodb.
        /// </summary>
        /// <param name="tableName">The name of the table to create.</param>
        /// <param name="tableThroughput">Initial provisioned throughput settings for the table.</param>
        /// <param name="indexThroughput">Initial provisioned throughput settings for the indexes.</param>
        public async void CreateTable(
            string tableName,
            ProvisionedThroughput tableThroughput,
            ProvisionedThroughput indexThroughput)
        {
            _logger.LogInformation("Starting CreateTable using table name {TableName}.", tableName);
            var request = 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 = tableThroughput
            };

            try
            {
                var response = await _amazonDynamoDB.CreateTableAsync(request);

                var tableDescription = response.TableDescription;
                _logger.LogInformation("{TableStatus}: {TableName} \t ReadsPerSec: {ReadCapacityUnits} \t WritesPerSec: {WriteCapacityUnits}",
                                       tableDescription.TableStatus,
                                       tableDescription.TableName,
                                       tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                       tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                string status = tableDescription.TableStatus;
                _logger.LogInformation("{TableName} - {Status}", tableName, status);

                if (status != "ACTIVE")
                {
                    //Await for table to be created
                    WaitUntilTableReady(tableName);
                }
            }
            catch (ResourceInUseException rx)
            {
                _logger.LogInformation("The table has already been created. {Message}", rx.Message);
            }
            catch (Exception ex)
            {
                _logger.LogError("There was a fatal error when provisioning dynamodb. {Exception}", ex);
                //throw exception and kill the service.
                throw ex;
            }
        }
        public async Task CreateTableAsync(int readCapacity = 1, int writecapacity = 1)
        {
            string tableName = TABLENAME;
            var    client    = Provider.DynamoDBClient;
            var    ptIndex   = new ProvisionedThroughput
            {
                ReadCapacityUnits  = readCapacity,
                WriteCapacityUnits = writecapacity
            };
            var subscriberIndex = new GlobalSecondaryIndex()
            {
                IndexName             = SelfModel.SCITagName,
                ProvisionedThroughput = ptIndex,
                KeySchema             =
                {
                    new KeySchemaElement {
                        AttributeName = "Subscriber", KeyType = "HASH" //Partition key
                    }
                },
                Projection = new Projection
                {
                    ProjectionType = "ALL"
                }
            };
            var response = await client.CreateTableAsync(new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Tag",               // Hash
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Subscriber",               // Range
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Tag",
                        KeyType       = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "Subscriber",
                        KeyType       = "RANGE"
                    }
                },
                ProvisionedThroughput  = ptIndex,
                GlobalSecondaryIndexes = { subscriberIndex }
            });

            WaitTillTableCreated(response).Wait();
        }
コード例 #11
0
 public DynamoDbCreateProvisionedThroughput(
     ProvisionedThroughput table = null,
     Dictionary <string, ProvisionedThroughput> gsiThroughputs = null)
 {
     //TODO: Sensible default value for table throughput?
     Table          = table ?? new ProvisionedThroughput(readCapacityUnits: 100, writeCapacityUnits: 100);
     GSIThroughputs = gsiThroughputs;
 }
コード例 #12
0
        private async Task EnsureInitializedImplAsync(IAmazonDynamoDB client, string rolesTableName)
        {
            var defaultProvisionThroughput = new ProvisionedThroughput
            {
                ReadCapacityUnits  = 5,
                WriteCapacityUnits = 5
            };
            var globalSecondaryIndexes = new List <GlobalSecondaryIndex>
            {
                new GlobalSecondaryIndex
                {
                    IndexName = "NormalizedName-DeletedOn-index",
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement("NormalizedName", KeyType.HASH),
                        new KeySchemaElement("DeletedOn", KeyType.RANGE)
                    },
                    ProvisionedThroughput = defaultProvisionThroughput,
                    Projection            = new Projection
                    {
                        ProjectionType = ProjectionType.ALL
                    }
                }
            };

            var tableNames = await client.ListAllTablesAsync();

            if (!tableNames.Contains(rolesTableName))
            {
                await CreateTableAsync(client, rolesTableName, defaultProvisionThroughput, globalSecondaryIndexes);

                return;
            }

            var response = await client.DescribeTableAsync(new DescribeTableRequest { TableName = rolesTableName });

            var table = response.Table;

            var indexesToAdd =
                globalSecondaryIndexes.Where(
                    g => !table.GlobalSecondaryIndexes.Exists(gd => gd.IndexName.Equals(g.IndexName)));
            var indexUpdates = indexesToAdd.Select(index => new GlobalSecondaryIndexUpdate
            {
                Create = new CreateGlobalSecondaryIndexAction
                {
                    IndexName             = index.IndexName,
                    KeySchema             = index.KeySchema,
                    ProvisionedThroughput = index.ProvisionedThroughput,
                    Projection            = index.Projection
                }
            }).ToList();

            if (indexUpdates.Count > 0)
            {
                await UpdateTableAsync(client, rolesTableName, indexUpdates);
            }
        }
コード例 #13
0
        private async Task CreateTable(string tableName, List <KeySchemaElement> keys, List <AttributeDefinition> attributes, List <GlobalSecondaryIndex> secondaryIndexes = null)
        {
            var useProvisionedThroughput = readCapacityUnits > 0 && writeCapacityUnits > 0;
            var request = new CreateTableRequest
            {
                TableName             = tableName,
                AttributeDefinitions  = attributes,
                KeySchema             = keys,
                BillingMode           = useProvisionedThroughput ? BillingMode.PROVISIONED : BillingMode.PAY_PER_REQUEST,
                ProvisionedThroughput = useProvisionedThroughput ? new ProvisionedThroughput
                {
                    ReadCapacityUnits  = readCapacityUnits,
                    WriteCapacityUnits = writeCapacityUnits
                } : null
            };

            if (secondaryIndexes != null && secondaryIndexes.Count > 0)
            {
                if (useProvisionedThroughput)
                {
                    var indexThroughput = new ProvisionedThroughput {
                        ReadCapacityUnits = readCapacityUnits, WriteCapacityUnits = writeCapacityUnits
                    };
                    secondaryIndexes.ForEach(i =>
                    {
                        i.ProvisionedThroughput = indexThroughput;
                    });
                }

                request.GlobalSecondaryIndexes = secondaryIndexes;
            }

            try
            {
                var response = await ddbClient.CreateTableAsync(request);

                TableDescription description = null;
                do
                {
                    description = await GetTableDescription(tableName);

                    await Task.Delay(2000);
                } while (description.TableStatus == TableStatus.CREATING);

                if (description.TableStatus != TableStatus.ACTIVE)
                {
                    throw new InvalidOperationException($"Failure creating table {tableName}");
                }
            }
            catch (Exception exc)
            {
                Logger.Error(ErrorCode.StorageProviderBase, $"Could not create table {tableName}", exc);
                throw;
            }
        }
コード例 #14
0
        public void CreateTable_ProperParams_CreatesTable()
        {
            var thru = new ProvisionedThroughput(1, 1);
            var keys = new List <DynamoDBKeyDescriptor>
            {
                new DynamoDBKeyDescriptor("year", DynamoDBKeyType.Hash, DynamoDBDataType.Number),
                new DynamoDBKeyDescriptor("title", DynamoDBKeyType.Range, DynamoDBDataType.String)
            };

            Sut.CreateTable("Movies", keys, thru);
        }
コード例 #15
0
        private async Task CreateTableAsync(IAmazonDynamoDB client, string userTableName,
                                            ProvisionedThroughput provisionedThroughput, List <GlobalSecondaryIndex> globalSecondaryIndexes)
        {
            var response = await client.CreateTableAsync(new CreateTableRequest
            {
                TableName             = userTableName,
                ProvisionedThroughput = provisionedThroughput,
                KeySchema             = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = KeyType.HASH
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "DeletedOn",
                        KeyType       = KeyType.RANGE
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "DeletedOn",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "NormalizedUserName",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "NormalizedEmail",
                        AttributeType = ScalarAttributeType.S
                    }
                },
                GlobalSecondaryIndexes = globalSecondaryIndexes
            });

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"Couldn't create table {userTableName}");
            }

            await DynamoUtils.WaitForActiveTableAsync(client, userTableName);
        }
コード例 #16
0
ファイル: DynamoDB.cs プロジェクト: arunksaini/EnquirySystem
        private void CreateTable(EntityType table)
        {
            // table_name
            var tableName = table.ToString();

            // key names for the table
            const string partitionKeyName = "Id";
            const string sortKeyName      = "TimeStamp";

            // items_attributes
            var itemsAttributes
                = new List <AttributeDefinition>
                {
                new AttributeDefinition
                {
                    AttributeName = partitionKeyName,
                    AttributeType = "N"
                },
                new AttributeDefinition
                {
                    AttributeName = sortKeyName,
                    AttributeType = "N"
                }
                };

            // key_schema
            var keySchema
                = new List <KeySchemaElement>
                {
                new KeySchemaElement
                {
                    AttributeName = partitionKeyName,
                    KeyType       = "HASH"
                },
                new KeySchemaElement
                {
                    AttributeName = sortKeyName,
                    KeyType       = "RANGE"
                }
                };


            var tableProvisionedThroughput
                = new ProvisionedThroughput(2, 1);

            Client.CreatingTable(tableName,
                                 itemsAttributes,
                                 keySchema,
                                 tableProvisionedThroughput);
        }
コード例 #17
0
        private async Task CreateTableAsync(IAmazonDynamoDB client, string tokenTableName,
                                            ProvisionedThroughput provisionedThroughput, List <GlobalSecondaryIndex> globalSecondaryIndexes)
        {
            var response = await client.CreateTableAsync(new CreateTableRequest
            {
                TableName             = tokenTableName,
                ProvisionedThroughput = provisionedThroughput,
                KeySchema             = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = KeyType.HASH
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Subject",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Application",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Authorization",
                        AttributeType = ScalarAttributeType.S
                    }
                },
                GlobalSecondaryIndexes = globalSecondaryIndexes
            });

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"Couldn't create table {tokenTableName}");
            }

            await DynamoUtils.WaitForActiveTableAsync(client, tokenTableName);
        }
コード例 #18
0
        /*--------------------------------------------------------------------------
         *                       CreatingTable
         *--------------------------------------------------------------------------*/
        public void CreatingTable(string newTableName,
                                  List <AttributeDefinition> tableAttributes,
                                  List <KeySchemaElement> tableKeySchema,
                                  ProvisionedThroughput provisionedThroughput)
        {
            if (CheckingTableExistence(newTableName) && CheckTableIsReady(newTableName))
            {
                return;
            }
            //Creating a new table

            CreateNewTable(newTableName,
                           tableAttributes,
                           tableKeySchema,
                           provisionedThroughput);
        }
コード例 #19
0
        public async Task CreateBooksTableAsync()
        {
            var keySchema = new List <KeySchemaElement>
            {
                new KeySchemaElement("Id", KeyType.HASH)
            };

            var attributes = new List <AttributeDefinition>
            {
                new AttributeDefinition("Id", ScalarAttributeType.S)
            };

            var throughput = new ProvisionedThroughput(readCapacityUnits: 5, writeCapacityUnits: 5);

            await _tableRepository.CreateTableAsync(TableName, keySchema, attributes, throughput);
        }
コード例 #20
0
        public IRequest Marshall(UpdateTableRequest updateTableRequest)
        {
            IRequest request = new DefaultRequest(updateTableRequest, "AmazonDynamoDB");
            string   target  = "DynamoDB_20111205.UpdateTable";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.0";

            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (updateTableRequest != null && updateTableRequest.IsSetTableName())
                {
                    writer.WritePropertyName("TableName");
                    writer.Write(updateTableRequest.TableName);
                }

                if (updateTableRequest != null)
                {
                    ProvisionedThroughput provisionedThroughput = updateTableRequest.ProvisionedThroughput;
                    if (provisionedThroughput != null)
                    {
                        writer.WritePropertyName("ProvisionedThroughput");
                        writer.WriteObjectStart();
                        if (provisionedThroughput != null && provisionedThroughput.IsSetReadCapacityUnits())
                        {
                            writer.WritePropertyName("ReadCapacityUnits");
                            writer.Write(provisionedThroughput.ReadCapacityUnits);
                        }
                        if (provisionedThroughput != null && provisionedThroughput.IsSetWriteCapacityUnits())
                        {
                            writer.WritePropertyName("WriteCapacityUnits");
                            writer.Write(provisionedThroughput.WriteCapacityUnits);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
                return(request);
            }
        }
コード例 #21
0
        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
            }
        }
コード例 #22
0
        public Task CreateTableAndWaitUntilTableReadyAsync(
            string tableName,
            IReadOnlyList <KeySchemaElement> keySchema,
            IReadOnlyList <AttributeDefinition> attributes,
            ProvisionedThroughput provisionedThroughput)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException($"Table name is required.", nameof(tableName));
            }

            return(createTableAndWaitAsync());

            async Task createTableAndWaitAsync()
            {
                await CreateTableAsync(tableName, keySchema, attributes, provisionedThroughput);
                await WaitUntilTableReadyAsync(tableName);
            }
        }
コード例 #23
0
        /*--------------------------------------------------------------------------
         *                CreateNewTable_async
         *--------------------------------------------------------------------------*/
        public static async Task <bool> CreateNewTable_async(string table_name,
                                                             List <AttributeDefinition> table_attributes,
                                                             List <KeySchemaElement> table_key_schema,
                                                             ProvisionedThroughput provisioned_throughput)
        {
            CreateTableRequest  request;
            CreateTableResponse response;

            // Build the 'CreateTableRequest' structure for the new table
            request = new CreateTableRequest
            {
                TableName            = table_name,
                AttributeDefinitions = table_attributes,
                KeySchema            = table_key_schema,
                // Provisioned-throughput settings are always required,
                // although the local test version of DynamoDB ignores them.
                ProvisionedThroughput = provisioned_throughput
            };

            operationSucceeded = false;
            operationFailed    = false;
            try
            {
                Task <CreateTableResponse> makeTbl = Ddb_Intro.client.CreateTableAsync(request);
                response = await makeTbl;
                Console.WriteLine("     -- Created the \"{0}\" table successfully!", table_name);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("     FAILED to create the new table, because: {0}.", ex.Message);
                operationFailed = true;
                return(false);
            }

            // Report the status of the new table...
            Console.WriteLine("     Status of the new table: '{0}'.", response.TableDescription.TableStatus);
            Ddb_Intro.moviesTableDescription = response.TableDescription;
            return(true);
        }
コード例 #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName">The table to be updated.</param>
        /// <param name="tableThroughput">Update provisioned throughput settings for the table.</param>
        /// <param name="indexThroughput">Update provisioned throughput settings for the indexes.</param>
        public async void UpdateTable(
            string tableName,
            ProvisionedThroughput tableThroughput,
            ProvisionedThroughput indexThroughput)
        {
            var request = new UpdateTableRequest()
            {
                TableName             = tableName,
                ProvisionedThroughput = tableThroughput
            };
            var response = await _amazonDynamoDB.UpdateTableAsync(request);

            var tableDescription = response.TableDescription;

            _logger.LogInformation("{TableStatus}: {TableName} \t ReadsPerSec: {ReadCapacityUnits} \t WritesPerSec: {WriteCapacityUnits}",
                                   tableDescription.TableStatus,
                                   tableDescription.TableName,
                                   tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                   tableDescription.ProvisionedThroughput.WriteCapacityUnits);

            WaitUntilTableReady(tableName);
        }
コード例 #25
0
        public override void Action(List <GlobalSecondaryIndexUpdate> indexUpdates, TableDescription tableDescription)
        {
            if (IndexDefinition.IsLocalIndex)
            {
                throw new InvalidOperationException("Cannot add local index. Local index can add when create table.");
            }

            var provisionedThroughput = new ProvisionedThroughput(
                tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                tableDescription.ProvisionedThroughput.WriteCapacityUnits
                );

            indexUpdates.Add(new GlobalSecondaryIndexUpdate
            {
                Create = new CreateGlobalSecondaryIndexAction
                {
                    IndexName             = IndexDefinition.IndexName,
                    Projection            = IndexDefinition.Projection,
                    KeySchema             = IndexDefinition.KeySchema,
                    ProvisionedThroughput = provisionedThroughput,
                }
            });
        }
コード例 #26
0
        public override async Task CreateTable()
        {
            var attributeDefinitions = new List <AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "Id",
                    // "S" = string, "N" = number, and so on.
                    AttributeType = "N"
                }
            };
            var keySchema = new List <KeySchemaElement>
            {
                new KeySchemaElement
                {
                    AttributeName = "Id",
                    // "HASH" = hash key, "RANGE" = range key.
                    KeyType = "HASH"
                }
            };
            var provisionedThroughput = new ProvisionedThroughput(5, 5);

            await CreateTable(tableName, attributeDefinitions, keySchema, provisionedThroughput);
        }
コード例 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TableOptions"/> class.
 /// </summary>
 /// <remarks>
 /// The following table shows the initial property values for an instance of <see cref="TableOptions"/>.
 /// <list type="table">
 ///     <listheader>
 ///         <term>Property</term>
 ///         <description>Initial Value</description>
 ///     </listheader>
 ///     <item>
 ///         <term><see cref="GlobalSecondaryIndexes"/></term>
 ///         <description>An empty collection of <see cref="SecondaryIndexCollection{GlobalSecondaryIndex}"/>.</description>
 ///     </item>
 ///     <item>
 ///         <term><see cref="StreamSpecification"/></term>
 ///         <description><c>null</c>.</description>
 ///     </item>
 ///     <item>
 ///         <term><see cref="Throughput"/></term>
 ///         <description>A new instance of <see cref="ProvisionedThroughput"/>.</description>
 ///     </item>
 /// </list>
 /// </remarks>
 public TableOptions()
 {
     GlobalSecondaryIndexes = new SecondaryIndexCollection <GlobalSecondaryIndex>();
     Throughput             = new ProvisionedThroughput(ThroughputOptions.DefaultReadCapacityUnits, ThroughputOptions.DefaultWriteCapacityUnits);
     StreamSpecification    = null;
 }
コード例 #28
0
        public CreateTableRequest CreateOutboxTableRequest(ProvisionedThroughput tableProvisionedThroughput, ProvisionedThroughput idGlobalIndexThroughput)
        {
            if (tableProvisionedThroughput is null)
            {
                throw new ArgumentNullException(nameof(tableProvisionedThroughput));
            }

            if (idGlobalIndexThroughput is null)
            {
                idGlobalIndexThroughput = tableProvisionedThroughput;
            }

            return(new CreateTableRequest
            {
                TableName = _tableName,
                ProvisionedThroughput = tableProvisionedThroughput,
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Topic+Date",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Time",
                        AttributeType = ScalarAttributeType.S
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "MessageId",
                        AttributeType = ScalarAttributeType.S
                    }
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Topic+Date",
                        KeyType = KeyType.HASH
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "Time",
                        KeyType = KeyType.RANGE
                    }
                },
                GlobalSecondaryIndexes = new List <GlobalSecondaryIndex>
                {
                    new GlobalSecondaryIndex
                    {
                        ProvisionedThroughput = idGlobalIndexThroughput,
                        IndexName = "MessageId",
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement
                            {
                                AttributeName = "MessageId",
                                KeyType = KeyType.HASH
                            }
                        },
                        Projection = new Projection
                        {
                            ProjectionType = ProjectionType.ALL
                        }
                    }
                }
            });
        }
コード例 #29
0
        private async Task EnsureInitializedImplAsync(IAmazonDynamoDB client, string authorizationTableName)
        {
            var defaultProvisionThroughput = new ProvisionedThroughput
            {
                ReadCapacityUnits  = 5,
                WriteCapacityUnits = 5
            };
            var globalSecondaryIndexes = new List <GlobalSecondaryIndex>
            {
                new GlobalSecondaryIndex
                {
                    IndexName = "Subject-Application-index",
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement("Subject", KeyType.HASH),
                        new KeySchemaElement("Application", KeyType.RANGE)
                    },
                    ProvisionedThroughput = defaultProvisionThroughput,
                    Projection            = new Projection
                    {
                        ProjectionType = ProjectionType.ALL
                    }
                }
            };

            var tablesResponse = await client.ListTablesAsync();

            if (tablesResponse.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Couldn't get list of tables");
            }
            var tableNames = tablesResponse.TableNames;

            if (!tableNames.Contains(authorizationTableName))
            {
                await CreateTableAsync(client, authorizationTableName, defaultProvisionThroughput, globalSecondaryIndexes);

                return;
            }

            var response = await client.DescribeTableAsync(new DescribeTableRequest { TableName = authorizationTableName });

            var table = response.Table;

            var indexesToAdd =
                globalSecondaryIndexes.Where(
                    g => !table.GlobalSecondaryIndexes.Exists(gd => gd.IndexName.Equals(g.IndexName)));
            var indexUpdates = indexesToAdd.Select(index => new GlobalSecondaryIndexUpdate
            {
                Create = new CreateGlobalSecondaryIndexAction
                {
                    IndexName             = index.IndexName,
                    KeySchema             = index.KeySchema,
                    ProvisionedThroughput = index.ProvisionedThroughput,
                    Projection            = index.Projection
                }
            }).ToList();

            if (indexUpdates.Count > 0)
            {
                await UpdateTableAsync(client, authorizationTableName, indexUpdates);
            }
        }
コード例 #30
0
        public async Task TestSourceFunctionAsyncRSMapIssue()
        {
            // Invoke the lambda function and confirm the string was upper cased.
            AmazonDynamoDBClient    client = new AmazonDynamoDBClient(RegionEndpoint.USEast1);
            List <KeySchemaElement> schema = new List <KeySchemaElement>
            {
                new KeySchemaElement
                {
                    AttributeName = "guid", KeyType = "HASH"
                },
                new KeySchemaElement
                {
                    AttributeName = "Data", KeyType = "RANGE"
                }
            };

            // Define key attributes:
            //  The key attributes "Author" and "Title" are string types
            List <AttributeDefinition> definitions = new List <AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "guid", AttributeType = "S"
                },
                new AttributeDefinition
                {
                    AttributeName = "Data", 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             = "MDSSourceDynamoDBTestDat1",
                KeySchema             = schema,
                ProvisionedThroughput = throughput,
                AttributeDefinitions  = definitions
            };


            // View new table properties
            var tableDescription = await client.CreateTableAsync(request);

            Console.WriteLine("Table name: {0}", tableDescription.TableDescription.TableName);
            Console.WriteLine("Creation time: {0}", tableDescription.TableDescription.CreationDateTime);
            Console.WriteLine("Item count: {0}", tableDescription.TableDescription.ItemCount);
            Console.WriteLine("Table size (bytes): {0}", tableDescription.TableDescription.TableSizeBytes);
            Console.WriteLine("Table status: {0}", tableDescription.TableDescription.TableStatus);
            //dbList.Add()

            Table  Catolog = Table.LoadTable(client, tableDescription.TableDescription.TableName);
            string status  = null;

            // Let us wait until table is created. Call DescribeTable.
            do
            {
                System.Threading.Thread.Sleep(5000); // Wait 5 seconds.
                try
                {
                    var res = await client.DescribeTableAsync(new DescribeTableRequest
                    {
                        TableName = "MDSSourceDynamoDBTestDat1"
                    });

                    Console.WriteLine("Table name: {0}, status: {1}",
                                      res.Table.TableName,
                                      res.Table.TableStatus);
                    status = res.Table.TableStatus;
                }
                catch (ResourceNotFoundException)
                {
                    // DescribeTable is eventually consistent. So you might
                    // get resource not found. So we handle the potential exception.
                }
            } while (status != "ACTIVE");
            Console.WriteLine("\n*** listing tables ***");

            IAmazonS3 s3Client              = new AmazonS3Client(RegionEndpoint.USEast1);
            string    inputData             = "#BUSINESS_DATE|CURRENCY|CREDIT_TYPE|RATINGS|TODAY|DAY_1|DAYS_7|DAYS_30|DAYS_90|DAYS_365|YEARS_2|YEARS_3|LOAD_DATE\n20190828|USD|CORPS|AAA|17.506131099768|17.499652220154|17.689977433049|17.612596564917|17.531741482981|16.721663421274|22.812501511208|28.591981044712|08/29/2019";
            var       destinationBucketName = "spgmi-dest-buck-test";
            var       bucketName            = "spgi-mds-data-dev-test2".ToLower();
            var       key = "MDR_EQUITY_PDR_ZSCORE_INCR_20191217032542.txt";

            // Create a bucket an object to setup a test data.
            await s3Client.PutBucketAsync(destinationBucketName);

            try
            {
                await s3Client.PutObjectAsync(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = inputData
                });

                // Setup the S3 event object that S3 notifications would create with the fields used by the Lambda function.
                var s3Event = new S3Event
                {
                    Records = new List <S3EventNotification.S3EventNotificationRecord>
                    {
                        new S3EventNotification.S3EventNotificationRecord
                        {
                            S3 = new S3EventNotification.S3Entity
                            {
                                Bucket = new S3EventNotification.S3BucketEntity {
                                    Name = bucketName
                                },
                                Object = new S3EventNotification.S3ObjectEntity {
                                    Key = key
                                }
                            }
                        }
                    }
                };
                var context = new TestLambdaContext();
                // Invoke the lambda function and confirm the content type was returned.
                var function    = new Function(s3Client);
                var contentType = await function.FunctionHandler(s3Event, context);

                Assert.Equal("text/plain", contentType);
            }
            catch (Exception ex)
            {
            }
        }