Container for the parameters to the CreateTable operation.

The CreateTable operation adds a new table to your account. In an AWS account, table names must be unique within each region. That is, you can have two tables with same name if you create the tables in different regions.

CreateTable is an asynchronous operation. Upon receiving a CreateTable request, Amazon DynamoDB immediately returns a response with a TableStatus of CREATING . After the table is created, Amazon DynamoDB sets the TableStatus to ACTIVE . You can perform read and write operations only on an ACTIVE table.

If you want to create multiple tables with local secondary indexes on them, you must create them sequentially. Only one table with local secondary indexes can be in the CREATING state at any given time.

You can use the DescribeTable API to check the table status.

Inheritance: AmazonDynamoDBv2Request
        public void CreateCallHistoryDetailsTable()
        {
            if (CheckTableExists(TABLE_CALL_HISTORY_DETAILS))
            {
                Console.WriteLine(TABLE_CALL_HISTORY_DETAILS + " table already exists");
                return;
            }

            try
            {
                List<AttributeDefinition> lstAttribDefinitions = new System.Collections.Generic.List<AttributeDefinition>();
                List<KeySchemaElement> lstSchemaElements = new List<KeySchemaElement>();
                ProvisionedThroughput throughput = new ProvisionedThroughput() { ReadCapacityUnits = 10, WriteCapacityUnits = 5 };

                lstAttribDefinitions.Add(new AttributeDefinition { AttributeName = "CallHistoryDetailsId", AttributeType = ScalarAttributeType.N });
                lstAttribDefinitions.Add(new AttributeDefinition { AttributeName = "UCID", AttributeType = ScalarAttributeType.N });

                lstSchemaElements.Add(new KeySchemaElement() { AttributeName = "UCID", KeyType = "HASH" });
                lstSchemaElements.Add(new KeySchemaElement() { AttributeName = "CallHistoryDetailsId", KeyType = "RANGE" });

                CreateTableRequest tbRequest = new CreateTableRequest(TABLE_CALL_HISTORY_DETAILS, lstSchemaElements, lstAttribDefinitions, throughput);

                var response = _client.CreateTable(tbRequest);

                WaitUntilTableReady(TABLE_CALL_HISTORY);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
示例#2
0
        protected Boolean CreateUserBudgetTable(DynamoDBContext context, string registerdUser)
        {
            Boolean created = false;
            Users currentUser = userCommon.GetUser(context, registerdUser);
            string tableName = $"BudgetLog_{currentUser.UserID}";
            var request = new CreateTableRequest
            {
                TableName = tableName,
                AttributeDefinitions = new List<AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "BudgetLogID",
                        AttributeType = "N"
                    }
                },
                KeySchema = new List<KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "BudgetLogID",
                        KeyType = "HASH"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 5,
                    WriteCapacityUnits = 2
                }
            };

            var response = client.CreateTable(request);
            int time = 0;
            var result = response.TableDescription;
            string status = result.TableStatus;
            if (status.ToLower() == "active")
                created = true;
            else
                created = false;

            while (!created)
            {
                time = time + 20;
                System.Threading.Thread.Sleep(20);
                var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName });

                if (res.Table.TableStatus.Value.ToLower() == "active")
                {
                    created = true;
                    break;
                }
                else
                    created = false;

                if (time == 1000)
                    break;
            }

            return created;
        }
        public virtual void BuildTable(AmazonDynamoDBClient ddbClient, string tableName)
        {
            Console.WriteLine("Creating table.");
            var request = new CreateTableRequest
            {
                TableName = tableName,
                AttributeDefinitions = new List<AttributeDefinition>
                {
                    new AttributeDefinition {AttributeName = "Company", AttributeType = "S"},
                    new AttributeDefinition {AttributeName = "Email", AttributeType = "S"}
                },
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement {AttributeName = "Company", KeyType = "HASH"},
                    new KeySchemaElement {AttributeName = "Email", KeyType = "RANGE"}
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 10,
                    WriteCapacityUnits = 5
                }
            };

            ddbClient.CreateTable(request);
            // Pause until the table is active
            WaitForStatus(ddbClient, tableName, "ACTIVE");
            Console.WriteLine("Table created and active.");
        }
        public void Create_Table_with_AWSSDK()
        {
            db.DeleteTable<Todo>();
            var request = new CreateTableRequest
            {
                TableName = "Todo",
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement("Id", KeyType.HASH),
                },
                AttributeDefinitions = new List<AttributeDefinition>
                {
                    new AttributeDefinition("Id", ScalarAttributeType.N),
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 10,
                    WriteCapacityUnits = 5,
                }
            };
            awsDb.CreateTable(request);

            while (true)
            {
                try
                {
                    var descResponse = awsDb.DescribeTable("Todo");
                    if (descResponse.Table.TableStatus == DynamoStatus.Active)
                        break;

                    Thread.Sleep(TimeSpan.FromSeconds(2));
                }
                catch (ResourceNotFoundException)
                {
                    // DescribeTable is eventually consistent. So you might get resource not found.
                }
            }

            var listResponse = awsDb.ListTables(new ListTablesRequest());
            var tableNames = listResponse.TableNames;
            tableNames.PrintDump();
        }
示例#5
0
        private void CreateTable()
        {
            var request = new CreateTableRequest
                {
                    AttributeDefinitions = _config.AttributeDefinitions,
                    KeySchema = _config.KeySchema,
                    ProvisionedThroughput = _config.ProvisionedThroughput,
                    TableName = _config.TableName
                };
            try
            {
                var response = _client.CreateTable(request);
                WaitUntilTableReady(_config.TableName);
            }
            catch (AmazonDynamoDBException ex)
            {
                if (!_expectedErrorCodesForConcurrentCalls.Contains(ex.ErrorCode))
                {
                    throw;
                }
            }


        }
		internal CreateTableResponse CreateTable(CreateTableRequest request)
        {
            var task = CreateTableAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
 /// <summary>
 /// The <i>CreateTable</i> operation adds a new table to your account. In an AWS account,
 /// table names must be unique within each region. That is, you can have two tables with
 /// same name if you create the tables in different regions.
 /// 
 ///  
 /// <para>
 /// <i>CreateTable</i> is an asynchronous operation. Upon receiving a <i>CreateTable</i>
 /// request, DynamoDB immediately returns a response with a <i>TableStatus</i> of <code>CREATING</code>.
 /// After the table is created, DynamoDB sets the <i>TableStatus</i> to <code>ACTIVE</code>.
 /// You can perform read and write operations only on an <code>ACTIVE</code> table. 
 /// </para>
 ///  
 /// <para>
 /// You can optionally define secondary indexes on the new table, as part of the <i>CreateTable</i>
 /// operation. If you want to create multiple tables with secondary indexes on them, you
 /// must create the tables sequentially. Only one table with secondary indexes can be
 /// in the <code>CREATING</code> state at any given time.
 /// </para>
 ///  
 /// <para>
 /// You can use the <i>DescribeTable</i> API to check the table status.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table to create.</param>
 /// <param name="keySchema">Specifies the attributes that make up the primary key for a table or an index. The attributes in <i>KeySchema</i> must also be defined in the <i>AttributeDefinitions</i> array. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html">Data Model</a> in the <i>Amazon DynamoDB Developer Guide</i>. Each <i>KeySchemaElement</i> in the array is composed of: <ul> <li> <i>AttributeName</i> - The name of this key attribute. </li> <li> <i>KeyType</i> - Determines whether the key attribute is <code>HASH</code> or <code>RANGE</code>. </li> </ul> For a primary key that consists of a hash attribute, you must provide exactly one element with a <i>KeyType</i> of <code>HASH</code>. For a primary key that consists of hash and range attributes, you must provide exactly two elements, in this order: The first element must have a <i>KeyType</i> of <code>HASH</code>, and the second element must have a <i>KeyType</i> of <code>RANGE</code>. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key">Specifying the Primary Key</a> in the <i>Amazon DynamoDB Developer Guide</i>.</param>
 /// <param name="attributeDefinitions">An array of attributes that describe the key schema for the table and indexes.</param>
 /// <param name="provisionedThroughput">A property of CreateTableRequest used to execute the CreateTable service method.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the CreateTable service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.LimitExceededException">
 /// The number of concurrent table requests (cumulative number of tables in the <code>CREATING</code>,
 /// <code>DELETING</code> or <code>UPDATING</code> state) exceeds the maximum allowed
 /// of 10.
 /// 
 ///  
 /// <para>
 /// Also, for tables with secondary indexes, only one of those tables can be in the <code>CREATING</code>
 /// state at any point in time. Do not attempt to create more than one such table simultaneously.
 /// </para>
 ///  
 /// <para>
 /// The total limit of tables in the <code>ACTIVE</code> state is 250.
 /// </para>
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceInUseException">
 /// The operation conflicts with the resource's availability. For example, you attempted
 /// to recreate an existing table, or tried to delete a table currently in the <code>CREATING</code>
 /// state.
 /// </exception>
 public Task<CreateTableResponse> CreateTableAsync(string tableName, List<KeySchemaElement> keySchema, List<AttributeDefinition> attributeDefinitions, ProvisionedThroughput provisionedThroughput, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new CreateTableRequest();
     request.TableName = tableName;
     request.KeySchema = keySchema;
     request.AttributeDefinitions = attributeDefinitions;
     request.ProvisionedThroughput = provisionedThroughput;
     return CreateTableAsync(request, cancellationToken);
 }
示例#8
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            DynamoDBContext context = new DynamoDBContext(client);

            string tableName = "BudgetsList";
            try
            {
                var exists = client.DescribeTable(tableName);
            }
            catch(Exception ex)// if fails to find budgetList (expection error) it creats the table so one should allways exist.
            {
                var request = new CreateTableRequest
                {
                    TableName = tableName,
                    AttributeDefinitions = new List<AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "BudgetID",
                        AttributeType = "N"
                    }
                },
                    KeySchema = new List<KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "BudgetID",
                        KeyType = "HASH"
                    }
                },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits = 5,
                        WriteCapacityUnits = 2
                    }
                };
                Boolean created = false;
                var response = client.CreateTable(request);
                int time = 0;
                var result = response.TableDescription;
                string status = result.TableStatus;
                if (status.ToLower() == "active")
                    created = true;
                else
                    created = false;

                while (!created)
                {
                    time = time + 20;
                    System.Threading.Thread.Sleep(20);
                    var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName });

                    if (res.Table.TableStatus.Value.ToLower() == "active")
                        break;

                    if (time == 1000)
                        break;
                }
            }
        }
        public void InitializeTable(string zipCodeData)
        {
            var listResponse = this._dbClient.ListTables(new ListTablesRequest
            {
                ExclusiveStartTableName = "ZipCode"
            });

            if (listResponse.TableNames.Count == 0)
            {
                var createRequest = new CreateTableRequest
                {
                    TableName = ZipCodeEntity.TableName,
                    KeySchema = new List<KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "PostalCode",
                            KeyType = KeyType.HASH
                        }
                    },
                    GlobalSecondaryIndexes = new List<GlobalSecondaryIndex>
                    {
                        new GlobalSecondaryIndex
                        {
                            IndexName = "State",
                            KeySchema = new List<KeySchemaElement>
                            {
                                new KeySchemaElement
                                {
                                    AttributeName = "StateAbbrevation",
                                    KeyType = KeyType.HASH
                                }
                            },
                            Projection = new Projection
                            {
                                ProjectionType = ProjectionType.ALL
                            },
                            ProvisionedThroughput = new ProvisionedThroughput
                            {
                                ReadCapacityUnits = 10,
                                WriteCapacityUnits = 1
                            }
                        }
                    },
                    AttributeDefinitions = new List<AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "PostalCode",
                            AttributeType = ScalarAttributeType.S
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "StateAbbrevation",
                            AttributeType = ScalarAttributeType.S
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits = 10,
                        WriteCapacityUnits = 1
                    }
                };
                this._dbClient.CreateTable(createRequest);

                DescribeTableResponse describeResponse = null;
                do
                {
                    Thread.Sleep(TimeSpan.FromSeconds(2));
                    describeResponse = this._dbClient.DescribeTable(ZipCodeEntity.TableName);
                } while (describeResponse.Table.TableStatus != TableStatus.ACTIVE);
            }

            using (StreamReader reader = new StreamReader(@"..\..\US-ZipCodes.txt"))
            {
                Console.WriteLine("Begin Upload");
                int count = 0;
                string line;
                HashSet<string> processedCodes = new HashSet<string>();
                var batchWrite = this._context.CreateBatchWrite<ZipCodeEntity>();
                while ((line = reader.ReadLine()) != null)
                {
                    var tokens = line.Split('\t');
                    if (tokens.Length != 12)
                        continue;

                    var code = new ZipCodeEntity
                    {
                        CountryCode = tokens[0],
                        PostalCode = tokens[1],
                        PlaceName = tokens[2],
                        State = tokens[3],
                        StateAbbrevation = tokens[4],
                        City = tokens[5],
                        Latitude = double.Parse(tokens[9]),
                        Longitude = double.Parse(tokens[10])
                    };

                    if (processedCodes.Contains(code.PostalCode))
                        continue;

                    processedCodes.Add(code.PostalCode);

                    batchWrite.AddPutItem(code);
                    count++;
                    if(count % 25 == 0)
                    {
                        batchWrite.Execute();
                        batchWrite = this._context.CreateBatchWrite<ZipCodeEntity>();
                        Console.WriteLine("...Uploaded {0}", count);
                    }
                }

                batchWrite.Execute();
                Console.WriteLine("Upload Complete {0}", count);
            }
        }
        public virtual void BuildTable(AmazonDynamoDBClient ddbClient, string tableName)
        {
            _Default.LogMessageToPage("Creating table.");
            var request = new CreateTableRequest
            {
                TableName = tableName,
                AttributeDefinitions = new List<AttributeDefinition>
                {
                    new AttributeDefinition {AttributeName = "Key", AttributeType = "S"},
                    new AttributeDefinition {AttributeName = "Bucket", AttributeType = "S"}
                },
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement {AttributeName = "Key", KeyType = "HASH"},
                    new KeySchemaElement {AttributeName = "Bucket", KeyType = "RANGE"}
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 5,
                    WriteCapacityUnits = 5
                }
            };

            ddbClient.CreateTable(request);
            // Pause until the table is active (timeout after 2 mins)
            WaitForStatus(ddbClient, tableName, "ACTIVE", DateTime.Now + TimeSpan.FromMinutes(2));
            _Default.LogMessageToPage("Table created and active.");
        }
 IAsyncResult invokeCreateTable(CreateTableRequest createTableRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new CreateTableRequestMarshaller().Marshall(createTableRequest);
     var unmarshaller = CreateTableResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
 /// <summary>
 /// Initiates the asynchronous execution of the CreateTable operation.
 /// <seealso cref="Amazon.DynamoDBv2.AmazonDynamoDB.CreateTable"/>
 /// </summary>
 /// 
 /// <param name="createTableRequest">Container for the necessary parameters to execute the CreateTable operation on AmazonDynamoDBv2.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateTable
 ///         operation.</returns>
 public IAsyncResult BeginCreateTable(CreateTableRequest createTableRequest, AsyncCallback callback, object state)
 {
     return invokeCreateTable(createTableRequest, callback, state, false);
 }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateTable operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB.CreateTable"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateTable operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<CreateTableResponse> CreateTableAsync(CreateTableRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateTableRequestMarshaller();
            var unmarshaller = CreateTableResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, CreateTableRequest, CreateTableResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
示例#14
0
        private void CreateTable()
        {
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();
            CreateTableRequest request = new CreateTableRequest
            {
                TableName = s_TableName,
                KeySchema = new List<KeySchemaElement>
                    {
                        new KeySchemaElement("Application", KeyType.HASH),
                        new KeySchemaElement("ErrorId", KeyType.RANGE),
                    },
                AttributeDefinitions = new List<AttributeDefinition>
                    {
                        new AttributeDefinition("Application", ScalarAttributeType.S),
                        new AttributeDefinition("ErrorId", ScalarAttributeType.S),
                        new AttributeDefinition("TimeUtc", ScalarAttributeType.S),
                        new AttributeDefinition("AllXml", ScalarAttributeType.S),
                    },
                GlobalSecondaryIndexes = new List<GlobalSecondaryIndex>
                    {
                        new GlobalSecondaryIndex
                        {
                            IndexName = "Application-TimeUtc-index",
                            KeySchema = new List<KeySchemaElement>
                            {
                                new KeySchemaElement("Application", KeyType.HASH),
                                new KeySchemaElement("TimeUtc", KeyType.RANGE),
                            }
                        },
                    },
                ProvisionedThroughput = new ProvisionedThroughput(40, 64),
                StreamSpecification = new StreamSpecification
                {
                    StreamEnabled = true,
                    StreamViewType = StreamViewType.NEW_IMAGE,
                },
            };

            CreateTableResponse response = client.CreateTable(request);
            if ((int)response.HttpStatusCode >= 400)
                throw new AmazonDynamoDBException(string.Format("CreateTable request ID {0} was unsuccessful.", response.ResponseMetadata.RequestId));
        }
示例#15
0
        static void Main(string[] args)
        {
            var config = new AmazonDynamoDBConfig();
            config.ServiceURL = "http://localhost:8000";
            AmazonDynamoDBClient client = new AmazonDynamoDBClient(config);
            string tableName = "MonthlyTotals";
            bool tableExists = false;
            string lastEvaluatedTableName = null;
            do
            {
                // Create a request object to specify optional parameters.
                var req = new ListTablesRequest
                {
                    Limit = 10, // Page size.
                    ExclusiveStartTableName = lastEvaluatedTableName
                };

                var tblres = client.ListTables(req);
                foreach (string name in tblres.TableNames) {
                    if (name.Equals(tableName))
                    {
                        tableExists = true;
                        break;
                    }
                }
                if (tableExists)
                {
                    break;
                }
                lastEvaluatedTableName = tblres.LastEvaluatedTableName;

            } while (lastEvaluatedTableName != null);

            if (!tableExists)
            {
                //Table doesnt exist, lets create it
                var request = new CreateTableRequest
                {
                    TableName = tableName,
                    AttributeDefinitions = new List<AttributeDefinition>()
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "SKUId",
                            AttributeType = "N"
                        },
                        new AttributeDefinition
                        {
                        AttributeName = "Month",
                        AttributeType = "S"
                        }
                    },
                        KeySchema = new List<KeySchemaElement>()
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "SKUId",
                            KeyType = "HASH"  //Partition key
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "Month",
                            KeyType = "RANGE"
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits = 10,
                        WriteCapacityUnits = 5
                    }
                };

                CreateTableResponse response = client.CreateTable(request);

                var tableDescription = response.TableDescription;
                Console.WriteLine("{1}: {0} \t ReadCapacityUnits: {2} \t WriteCapacityUnits: {3}",
                                tableDescription.TableStatus,
                                tableDescription.TableName,
                                tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                string status = tableDescription.TableStatus;
            }

            var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName });
            Console.WriteLine(tableName + " - " + res.Table.TableStatus);
            Console.WriteLine();
            Console.WriteLine("Test Crud?");
            Console.ReadLine();

            DynamoDBContext context = new DynamoDBContext(client);
            TestCRUDOperations(context);
            Console.ReadLine();
        }
示例#16
0
        private void CreateLSITable()
        {
            #region CreateTable LSI Sample

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

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

            // Define local secondary indexes:
            //  Table has two indexes, one on "Year" and the other on "Setting"
            List<LocalSecondaryIndex> indexes = new List<LocalSecondaryIndex>
            {
                new LocalSecondaryIndex
                {
                    IndexName = "YearsIndex",
                    KeySchema = new List<KeySchemaElement>
                    {
                        // Hash key must match table hash key
                        new KeySchemaElement { AttributeName = "Author", KeyType = "HASH" },
                        // Secondary index on "Year" attribute
                        new KeySchemaElement { AttributeName = "Year", KeyType = "RANGE" }
                    },
                    // Projection type is set to ALL, all attributes returned for this index
                    Projection = new Projection
                    {
                        ProjectionType = "ALL"
                    }
                },
                new LocalSecondaryIndex
                {
                    IndexName = "SettingsIndex",
                    KeySchema = new List<KeySchemaElement>
                    {
                        // Hash key must match table hash key
                        new KeySchemaElement { AttributeName = "Author", KeyType = "HASH" },
                        // Secondary index on "Setting" attribute
                        new KeySchemaElement { AttributeName = "Setting", KeyType = "RANGE" }
                    },
                    // Projection type is set to INCLUDE, the specified attributes + keys are returned
                    Projection = new Projection
                    {
                        ProjectionType = "INCLUDE",
                        NonKeyAttributes = new List<string>
                        {
                            "Pages", "Genres"
                        }
                    }
                }
            };

            // Define key attributes:
            //  The key attributes "Author" and "Title" are string types.
            //  The local secondary index attributes are "Year" (numerical) and "Setting" (string).
            List<AttributeDefinition> definitions = new List<AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "Author", AttributeType = "S"
                },
                new AttributeDefinition
                {
                    AttributeName = "Title", AttributeType = "S"
                },
                new AttributeDefinition
                {
                    AttributeName = "Year", AttributeType = "N"
                },
                new AttributeDefinition
                {
                    AttributeName = "Setting", AttributeType = "S"
                }
            };

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

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

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

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

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

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

            #endregion
        }
示例#17
0
        public void DataPlaneSamples()
        {
            {
                #region CreateTable Sample

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

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

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

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

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

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

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

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

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

                #endregion
            }

            {
                #region DescribeTable Sample

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

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

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

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

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

                #endregion
            }

            {
                #region ListTables Paging Sample

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

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

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

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

                    // Update marker value from the result
                    startTableName = result.LastEvaluatedTableName;

                } while (!string.IsNullOrEmpty(startTableName)); // Test marker value

                #endregion
            }

            {
                #region ListTables NonPaging Sample

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

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

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

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region UpdateTable Sample

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

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

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

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

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region DeleteTable Sample

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

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

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

                #endregion
            }

        }
 /// <summary>
 /// Initiates the asynchronous execution of the CreateTable operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the CreateTable operation on AmazonDynamoDBClient.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void CreateTableAsync(CreateTableRequest request, AmazonServiceCallback<CreateTableRequest, CreateTableResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new CreateTableRequestMarshaller();
     var unmarshaller = CreateTableResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<CreateTableRequest,CreateTableResponse> responseObject 
                     = new AmazonServiceResult<CreateTableRequest,CreateTableResponse>((CreateTableRequest)req, (CreateTableResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<CreateTableRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
 /// <summary>
 /// The <i>CreateTable</i> operation adds a new table to your account. In an AWS account,
 /// table names must be unique within each region. That is, you can have two tables with
 /// same name if you create the tables in different regions.
 /// 
 ///  
 /// <para>
 /// <i>CreateTable</i> is an asynchronous operation. Upon receiving a <i>CreateTable</i>
 /// request, DynamoDB immediately returns a response with a <i>TableStatus</i> of <code>CREATING</code>.
 /// After the table is created, DynamoDB sets the <i>TableStatus</i> to <code>ACTIVE</code>.
 /// You can perform read and write operations only on an <code>ACTIVE</code> table. 
 /// </para>
 ///  
 /// <para>
 /// You can optionally define secondary indexes on the new table, as part of the <i>CreateTable</i>
 /// operation. If you want to create multiple tables with secondary indexes on them, you
 /// must create the tables sequentially. Only one table with secondary indexes can be
 /// in the <code>CREATING</code> state at any given time.
 /// </para>
 ///  
 /// <para>
 /// You can use the <i>DescribeTable</i> API to check the table status.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table to create.</param>
 /// <param name="keySchema">Specifies the attributes that make up the primary key for a table or an index. The attributes in <i>KeySchema</i> must also be defined in the <i>AttributeDefinitions</i> array. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html">Data Model</a> in the <i>Amazon DynamoDB Developer Guide</i>. Each <i>KeySchemaElement</i> in the array is composed of: <ul> <li> <i>AttributeName</i> - The name of this key attribute. </li> <li> <i>KeyType</i> - Determines whether the key attribute is <code>HASH</code> or <code>RANGE</code>. </li> </ul> For a primary key that consists of a hash attribute, you must provide exactly one element with a <i>KeyType</i> of <code>HASH</code>. For a primary key that consists of hash and range attributes, you must provide exactly two elements, in this order: The first element must have a <i>KeyType</i> of <code>HASH</code>, and the second element must have a <i>KeyType</i> of <code>RANGE</code>. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key">Specifying the Primary Key</a> in the <i>Amazon DynamoDB Developer Guide</i>.</param>
 /// <param name="attributeDefinitions">An array of attributes that describe the key schema for the table and indexes.</param>
 /// <param name="provisionedThroughput">A property of CreateTableRequest used to execute the CreateTable service method.</param>
 /// 
 /// <returns>The response from the CreateTable service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.LimitExceededException">
 /// The number of concurrent table requests (cumulative number of tables in the <code>CREATING</code>,
 /// <code>DELETING</code> or <code>UPDATING</code> state) exceeds the maximum allowed
 /// of 10.
 /// 
 ///  
 /// <para>
 /// Also, for tables with secondary indexes, only one of those tables can be in the <code>CREATING</code>
 /// state at any point in time. Do not attempt to create more than one such table simultaneously.
 /// </para>
 ///  
 /// <para>
 /// The total limit of tables in the <code>ACTIVE</code> state is 250.
 /// </para>
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceInUseException">
 /// The operation conflicts with the resource's availability. For example, you attempted
 /// to recreate an existing table, or tried to delete a table currently in the <code>CREATING</code>
 /// state.
 /// </exception>
 public void CreateTableAsync(string tableName, List<KeySchemaElement> keySchema, List<AttributeDefinition> attributeDefinitions, ProvisionedThroughput provisionedThroughput, AmazonServiceCallback<CreateTableRequest, CreateTableResponse> callback, AsyncOptions options = null)
 {
     var request = new CreateTableRequest();
     request.TableName = tableName;
     request.KeySchema = keySchema;
     request.AttributeDefinitions = attributeDefinitions;
     request.ProvisionedThroughput = provisionedThroughput;
     CreateTableAsync(request, callback, options);
 }
        /// <summary>
        /// <para>The <i>CreateTable</i> operation adds a new table to your account. In an AWS account, table names must be unique within each region.
        /// That is, you can have two tables with same name if you create the tables in different regions.</para> <para> <i>CreateTable</i> is an
        /// asynchronous operation. Upon receiving a <i>CreateTable</i> request, DynamoDB immediately returns a response with a <i>TableStatus</i> of
        /// <c>CREATING</c> . After the table is created, DynamoDB sets the <i>TableStatus</i> to <c>ACTIVE</c> . You can perform read and write
        /// operations only on an <c>ACTIVE</c> table. </para> <para>If you want to create multiple tables with secondary indexes on them, you must
        /// create them sequentially. Only one table with secondary indexes can be in the <c>CREATING</c> state at any given time.</para> <para>You can
        /// use the <i>DescribeTable</i> API to check the table status.</para>
        /// </summary>
        /// 
        /// <param name="createTableRequest">Container for the necessary parameters to execute the CreateTable service method on
        /// AmazonDynamoDBv2.</param>
        /// 
        /// <returns>The response from the CreateTable service method, as returned by AmazonDynamoDBv2.</returns>
        /// 
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceInUseException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.LimitExceededException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.InternalServerErrorException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<CreateTableResponse> CreateTableAsync(CreateTableRequest createTableRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateTableRequestMarshaller();
            var unmarshaller = CreateTableResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, CreateTableRequest, CreateTableResponse>(createTableRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
 /// <summary>
 /// The <i>CreateTable</i> operation adds a new table to your account. In an AWS account,
 /// table names must be unique within each region. That is, you can have two tables with
 /// same name if you create the tables in different regions.
 /// 
 ///  
 /// <para>
 /// <i>CreateTable</i> is an asynchronous operation. Upon receiving a <i>CreateTable</i>
 /// request, DynamoDB immediately returns a response with a <i>TableStatus</i> of <code>CREATING</code>.
 /// After the table is created, DynamoDB sets the <i>TableStatus</i> to <code>ACTIVE</code>.
 /// You can perform read and write operations only on an <code>ACTIVE</code> table. 
 /// </para>
 ///  
 /// <para>
 /// You can optionally define secondary indexes on the new table, as part of the <i>CreateTable</i>
 /// operation. If you want to create multiple tables with secondary indexes on them, you
 /// must create the tables sequentially. Only one table with secondary indexes can be
 /// in the <code>CREATING</code> state at any given time.
 /// </para>
 ///  
 /// <para>
 /// You can use the <i>DescribeTable</i> API to check the table status.
 /// </para>
 /// </summary>
 /// <param name="tableName">The name of the table to create.</param>
 /// <param name="keySchema">Specifies the attributes that make up the primary key for a table or an index. The attributes in <i>KeySchema</i> must also be defined in the <i>AttributeDefinitions</i> array. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html">Data Model</a> in the <i>Amazon DynamoDB Developer Guide</i>. Each <i>KeySchemaElement</i> in the array is composed of: <ul> <li> <i>AttributeName</i> - The name of this key attribute. </li> <li> <i>KeyType</i> - Determines whether the key attribute is <code>HASH</code> or <code>RANGE</code>. </li> </ul> For a primary key that consists of a hash attribute, you must provide exactly one element with a <i>KeyType</i> of <code>HASH</code>. For a primary key that consists of hash and range attributes, you must provide exactly two elements, in this order: The first element must have a <i>KeyType</i> of <code>HASH</code>, and the second element must have a <i>KeyType</i> of <code>RANGE</code>. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key">Specifying the Primary Key</a> in the <i>Amazon DynamoDB Developer Guide</i>.</param>
 /// <param name="attributeDefinitions">An array of attributes that describe the key schema for the table and indexes.</param>
 /// <param name="provisionedThroughput">A property of CreateTableRequest used to execute the CreateTable service method.</param>
 /// 
 /// <returns>The response from the CreateTable service method, as returned by DynamoDB.</returns>
 /// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
 /// An error occurred on the server side.
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.LimitExceededException">
 /// The number of concurrent table requests (cumulative number of tables in the <code>CREATING</code>,
 /// <code>DELETING</code> or <code>UPDATING</code> state) exceeds the maximum allowed
 /// of 10.
 /// 
 ///  
 /// <para>
 /// Also, for tables with secondary indexes, only one of those tables can be in the <code>CREATING</code>
 /// state at any point in time. Do not attempt to create more than one such table simultaneously.
 /// </para>
 ///  
 /// <para>
 /// The total limit of tables in the <code>ACTIVE</code> state is 250.
 /// </para>
 /// </exception>
 /// <exception cref="Amazon.DynamoDBv2.Model.ResourceInUseException">
 /// The operation conflicts with the resource's availability. For example, you attempted
 /// to recreate an existing table, or tried to delete a table currently in the <code>CREATING</code>
 /// state.
 /// </exception>
 public CreateTableResponse CreateTable(string tableName, List<KeySchemaElement> keySchema, List<AttributeDefinition> attributeDefinitions, ProvisionedThroughput provisionedThroughput)
 {
     var request = new CreateTableRequest();
     request.TableName = tableName;
     request.KeySchema = keySchema;
     request.AttributeDefinitions = attributeDefinitions;
     request.ProvisionedThroughput = provisionedThroughput;
     return CreateTable(request);
 }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateTable operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateTable operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<CreateTableResponse> CreateTableAsync(CreateTableRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateTableRequestMarshaller();
            var unmarshaller = CreateTableResponseUnmarshaller.Instance;

            return InvokeAsync<CreateTableRequest,CreateTableResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
 /// <summary>
 /// <para>The <i>CreateTable</i> operation adds a new table to your account. In an AWS account, table names must be unique within each region.
 /// That is, you can have two tables with same name if you create the tables in different regions.</para> <para> <i>CreateTable</i> is an
 /// asynchronous operation. Upon receiving a <i>CreateTable</i> request, Amazon DynamoDB immediately returns a response with a
 /// <i>TableStatus</i> of <c>CREATING</c> . After the table is created, Amazon DynamoDB sets the <i>TableStatus</i> to <c>ACTIVE</c> . You can
 /// perform read and write operations only on an <c>ACTIVE</c> table. </para> <para>If you want to create multiple tables with local secondary
 /// indexes on them, you must create them sequentially. Only one table with local secondary indexes can be in the <c>CREATING</c> state at any
 /// given time.</para> <para>You can use the <i>DescribeTable</i> API to check the table status.</para>
 /// </summary>
 /// 
 /// <param name="createTableRequest">Container for the necessary parameters to execute the CreateTable service method on
 ///          AmazonDynamoDBv2.</param>
 /// 
 /// <returns>The response from the CreateTable service method, as returned by AmazonDynamoDBv2.</returns>
 /// 
 /// <exception cref="ResourceInUseException"/>
 /// <exception cref="LimitExceededException"/>
 /// <exception cref="InternalServerErrorException"/>
 public CreateTableResponse CreateTable(CreateTableRequest createTableRequest)
 {
     IAsyncResult asyncResult = invokeCreateTable(createTableRequest, null, null, true);
     return EndCreateTable(asyncResult);
 }
示例#24
0
        void CreateTableListener()
        {
            resultText.text = @"\n Creating table";

            var productCatalogTableRequest = new CreateTableRequest
            {
                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
                },
                TableName = "ProductCatalog"
            };

            Client.CreateTableAsync(productCatalogTableRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    resultText.text += result.Exception.Message;
                    return;
                }
                var tableDescription = result.Response.TableDescription;
                resultText.text += String.Format("Created {1}: {0}\nReadsPerSec: {2} \nWritesPerSec: {3}\n",
                              tableDescription.TableStatus,
                              tableDescription.TableName,
                              tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                              tableDescription.ProvisionedThroughput.WriteCapacityUnits);
                resultText.text += (result.Request.TableName + "-" + tableDescription.TableStatus + "\n");
                resultText.text += ("Allow a few seconds for changes to reflect...");
            });


            var forumTableRequest = new CreateTableRequest
            {
                AttributeDefinitions = new List<AttributeDefinition>()
                {
                        new AttributeDefinition
                        {
                                AttributeName = "Name",
                                AttributeType = "S"
                        }
                },
                KeySchema = new List<KeySchemaElement>
                {
                        new KeySchemaElement
                        {
                                AttributeName = "Name",
                                KeyType = "HASH"
                        }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 10,
                    WriteCapacityUnits = 5
                },
                TableName = "Forum"
            };

            Client.CreateTableAsync(forumTableRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    resultText.text += result.Exception.Message;
                    return;
                }
                var tableDescription = result.Response.TableDescription;
                resultText.text += String.Format("Created {1}: {0}\nReadsPerSec: {2} \nWritesPerSec: {3}\n",
                                                tableDescription.TableStatus,
                                                tableDescription.TableName,
                                                tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                                tableDescription.ProvisionedThroughput.WriteCapacityUnits);
                resultText.text += (result.Request.TableName + "-" + tableDescription.TableStatus + "\n");
                resultText.text += ("Allow a few seconds for changes to reflect...");
            });

            var threadTableRequest = new CreateTableRequest
            {
                AttributeDefinitions = new List<AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                            AttributeName = "ForumName",
                            AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                            AttributeName = "Subject",
                            AttributeType = "S"
                    }
                },
                KeySchema = new List<KeySchemaElement>
                {
                        new KeySchemaElement
                        {
                            AttributeName = "ForumName",
                            KeyType = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "Subject",
                            KeyType = "RANGE"
                        }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 10,
                    WriteCapacityUnits = 5
                },
                TableName = "Thread"
            };

            Client.CreateTableAsync(threadTableRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    resultText.text += result.Exception.Message;
                    return;
                }
                var tableDescription = result.Response.TableDescription;
                resultText.text += String.Format("Created {1}: {0}\nReadsPerSec: {2} \nWritesPerSec: {3}\n",
                                                tableDescription.TableStatus,
                                                tableDescription.TableName,
                                                tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                                tableDescription.ProvisionedThroughput.WriteCapacityUnits);
                resultText.text += (result.Request.TableName + "-" + tableDescription.TableStatus + "\n");
                resultText.text += ("Allow a few seconds for changes to reflect...");
            });

            var replyTableRequest = new CreateTableRequest
            {
                AttributeDefinitions = new List<AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "ReplyDateTime",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "PostedBy",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType = KeyType.HASH
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "ReplyDateTime",
                        KeyType = KeyType.RANGE
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = 10,
                    WriteCapacityUnits = 5
                },
                LocalSecondaryIndexes = new List<LocalSecondaryIndex>()
                {
                    new LocalSecondaryIndex()
                    {
                        IndexName="PostedBy-index",
                        KeySchema = new List<KeySchemaElement>()
                        {
                            new KeySchemaElement()
                            {
                                    AttributeName = "Id",
                                    KeyType = KeyType.HASH
                            },
                            new KeySchemaElement
                            {
                                AttributeName = "PostedBy",
                                KeyType = KeyType.RANGE
                            }
                        },
                        Projection = new Projection()
                        {
                            ProjectionType = ProjectionType.KEYS_ONLY
                        }
                    }
                },
                TableName = "Reply"
            };

            Client.CreateTableAsync(replyTableRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    resultText.text += result.Exception.Message;
                    return;
                }
                var tableDescription = result.Response.TableDescription;
                resultText.text += String.Format("Created {1}: {0}\nReadsPerSec: {2} \nWritesPerSec: {3}\n",
                                                tableDescription.TableStatus,
                                                tableDescription.TableName,
                                                tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                                tableDescription.ProvisionedThroughput.WriteCapacityUnits);
                resultText.text += (result.Request.TableName + "-" + tableDescription.TableStatus + "\n");
                resultText.text += ("Allow a few seconds for changes to reflect...");
            });
        }
        internal CreateTableResponse CreateTable(CreateTableRequest request)
        {
            var marshaller = new CreateTableRequestMarshaller();
            var unmarshaller = CreateTableResponseUnmarshaller.Instance;

            return Invoke<CreateTableRequest,CreateTableResponse>(request, marshaller, unmarshaller);
        }
 internal static Task<CreateTableResponse> CreateTableAsync(this Amazon.DynamoDBv2.AmazonDynamoDB client, CreateTableRequest request)
 {
     return Task.Factory.FromAsync(client.BeginCreateTable, (Func<IAsyncResult, CreateTableResponse>) client.EndCreateTable, request, null);
 }
        private Amazon.DynamoDBv2.Model.CreateTableResponse CallAWSServiceOperation(IAmazonDynamoDB client, Amazon.DynamoDBv2.Model.CreateTableRequest request)
        {
            Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon DynamoDB", "CreateTable");

            try
            {
#if DESKTOP
                return(client.CreateTable(request));
#elif CORECLR
                return(client.CreateTableAsync(request).GetAwaiter().GetResult());
#else
#error "Unknown build edition"
#endif
            }
            catch (AmazonServiceException exc)
            {
                var webException = exc.InnerException as System.Net.WebException;
                if (webException != null)
                {
                    throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
                }

                throw;
            }
        }
示例#28
0
		internal CreateTableResponse CreateTable(CreateTableRequest request)
        {
            var task = CreateTableAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        private Table CreateTable()
        {
            CreateTableRequest createRequest = new CreateTableRequest
            {
                TableName = this._tableName,
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = ATTRIBUTE_SESSION_ID, KeyType = "HASH"
                    }
                },
                AttributeDefinitions = new List<AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = ATTRIBUTE_SESSION_ID, AttributeType = "S"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits = this._initialReadUnits,
                    WriteCapacityUnits = this._initialWriteUnits
                }
            };

            CreateTableResponse response = this._ddbClient.CreateTable(createRequest);

            DescribeTableRequest descRequest = new DescribeTableRequest
            {
                TableName = this._tableName
            };

            // Wait till table is active
            bool isActive = false;
            while (!isActive)
            {
                Thread.Sleep(DESCRIBE_INTERVAL);
                DescribeTableResponse descResponse = this._ddbClient.DescribeTable(descRequest);
                string tableStatus = descResponse.Table.TableStatus;

                if (string.Equals(tableStatus, ACTIVE_STATUS, StringComparison.InvariantCultureIgnoreCase))
                    isActive = true;
            }

            Table table = Table.LoadTable(this._ddbClient, this._tableName, DynamoDBEntryConversion.V1);
            return table;
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateTable operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateTable operation on AmazonDynamoDBClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateTable
        ///         operation.</returns>
        public IAsyncResult BeginCreateTable(CreateTableRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new CreateTableRequestMarshaller();
            var unmarshaller = CreateTableResponseUnmarshaller.Instance;

            return BeginInvoke<CreateTableRequest>(request, marshaller, unmarshaller,
                callback, state);
        }