DescribeTable() public method

Returns information about the table, including the current status of the table, when it was created, the primary key schema, and any indexes on the table.

If you issue a DescribeTable request immediately after a CreateTable request, DynamoDB might return a ResourceNotFoundException. This is because DescribeTable uses an eventually consistent query, and the metadata for your table might not be available at that moment. Wait for a few seconds, and then try the DescribeTable request again.

/// An error occurred on the server side. /// /// The operation tried to access a nonexistent table or index. The resource might not /// be specified correctly, or its status might not be ACTIVE. ///
public DescribeTable ( DescribeTableRequest request ) : DescribeTableResponse
request Amazon.DynamoDBv2.Model.DescribeTableRequest Container for the necessary parameters to execute the DescribeTable service method.
return Amazon.DynamoDBv2.Model.DescribeTableResponse
コード例 #1
0
        private void WaitTillTableDeleted(AmazonDynamoDBClient client, string tableName) {
            Console.Write("Deleting the table: ");
            string status;
            try {
                do {
                    System.Threading.Thread.Sleep(50);

                    var res = client.DescribeTable(new DescribeTableRequest
                    {
                        TableName = tableName
                    });
                    if (res.Table.TableStatus == "DELETING") {
                        Console.Write(".");
                    }
                    else {
                        Console.Write("[{0}]", res.Table.TableStatus);
                    }
                    status = res.Table.TableStatus;
                }
                while (status == "DELETING");
            }
            catch (ResourceNotFoundException) {
                Console.WriteLine(" Done.");
            }
        }
コード例 #2
0
        private void WaitTillTableCreated(AmazonDynamoDBClient client, string tableName) {
            string status;

            Console.Write("Creating the table: ");
            do {
                System.Threading.Thread.Sleep(50);
                try {
                    var res = client.DescribeTable(new DescribeTableRequest
                    {
                        TableName = tableName
                    });
                    if (res.Table.TableStatus == "ACTIVE") {
                        break;
                    }
                    if (res.Table.TableStatus == "CREATING") {
                        Console.Write(".");
                    }
                    else {
                        Console.Write("[{0}]", res.Table.TableStatus);
                    }

                    status = res.Table.TableStatus;
                }
                catch (ResourceNotFoundException) {
                    Console.Write("?");  // Okay to appear, since the consistency is eventual.
                    status = "EXCEPTION";
                }
            } while (status != "ACTIVE");
            Console.WriteLine(" Done.");
        }
コード例 #3
0
 /// <summary>
 /// Retrieves a table status. Returns empty string if table does not exist.
 /// </summary>
 /// <param name="client"></param>
 /// <param name="tableName"></param>
 /// <returns></returns>
 private static TableStatus GetTableStatus(AmazonDynamoDBClient client, string tableName)
 {
     try
     {
         var table = client.DescribeTable(new DescribeTableRequest { TableName = tableName }).Table;
         return (table == null) ? null : table.TableStatus;
     }
     catch (AmazonDynamoDBException db)
     {
         if (db.ErrorCode == "ResourceNotFoundException")
             return string.Empty;
         throw;
     }
 }
コード例 #4
0
        // Test exception parsing with selected services
        public void TestExceptions()
        {
            var fakeData = "obviously-super-duper-fake-data";

            using (var client = new Amazon.Lightsail.AmazonLightsailClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.Lightsail.Model.NotFoundException>(() =>
                {
                    client.GetInstance(new Amazon.Lightsail.Model.GetInstanceRequest
                    {
                        InstanceName = fakeData
                    });
                });
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var client = new Amazon.ElasticTranscoder.AmazonElasticTranscoderClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.ElasticTranscoder.Model.ValidationException>(() =>
                {
                    client.DeletePipeline(new Amazon.ElasticTranscoder.Model.DeletePipelineRequest
                    {
                        Id = fakeData
                    });
                });
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var ddb = new Amazon.DynamoDBv2.AmazonDynamoDBClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.DynamoDBv2.Model.ResourceNotFoundException>(() => ddb.DescribeTable("fakey-mcfake-table"));
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var client = new Amazon.Pinpoint.AmazonPinpointClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.Pinpoint.Model.NotFoundException>(() =>
                {
                    client.DeleteCampaign(new Amazon.Pinpoint.Model.DeleteCampaignRequest
                    {
                        ApplicationId = fakeData,
                        CampaignId    = fakeData
                    });
                });
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var client = new Amazon.Batch.AmazonBatchClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.Batch.Model.ClientException>(() =>
                {
                    client.UpdateComputeEnvironment(new Amazon.Batch.Model.UpdateComputeEnvironmentRequest
                    {
                        ComputeEnvironment = fakeData
                    });
                });
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var client = new Amazon.Glacier.AmazonGlacierClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.Glacier.Model.ResourceNotFoundException>(() =>
                {
                    client.InitiateMultipartUpload(new Amazon.Glacier.Model.InitiateMultipartUploadRequest
                    {
                        AccountId          = "-",
                        ArchiveDescription = fakeData,
                        VaultName          = fakeData,
                        PartSize           = 123
                    });
                });
                Assert.AreEqual(ErrorType.Unknown, ex.ErrorType);
            }

            using (var client = new Amazon.IdentityManagement.AmazonIdentityManagementServiceClient())
            {
                var ex = AssertExtensions.ExpectException <Amazon.IdentityManagement.Model.NoSuchEntityException>(() =>
                {
                    client.AttachGroupPolicy(new Amazon.IdentityManagement.Model.AttachGroupPolicyRequest
                    {
                        PolicyArn = fakeData,
                        GroupName = fakeData
                    });
                });
                Assert.AreEqual(ErrorType.Sender, ex.ErrorType);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: wildbillcat/Dynamo
        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();
        }
コード例 #6
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
            }

        }
コード例 #7
0
        public virtual TableDescription GetTableDescription(AmazonDynamoDBClient ddbClient, string tableName)
        {
            try
            {
                DescribeTableResponse describeTableResponse = ddbClient.DescribeTable(
                    new DescribeTableRequest
                    {
                        TableName = tableName
                    });

                return describeTableResponse.Table;
            }
            catch (AmazonServiceException ase)
            {
                // If the table isn't found, there's no problem.
                // If the error is something else, rethrow the exception to bubble it up to the caller.
                if (!ase.ErrorCode.Equals("ResourceNotFoundException"))
                {
                    throw;
                }
                return null;
            }
        }