- DynamoDB - Best Practices
- DynamoDB - Error Handling
- DynamoDB - Table Activity
- DynamoDB - MapReduce
- DynamoDB - CloudTrail
- DynamoDB - Monitoring
- DynamoDB - Data Backup
- DynamoDB - Data Pipeline
- Web Identity Federation
- DynamoDB - Conditions
- DynamoDB - Permissions API
- DynamoDB - Access Control
- DynamoDB - Aggregation
- Local Secondary Indexes
- Global Secondary Indexes
- DynamoDB - Indexes
- DynamoDB - Scan
- DynamoDB - Querying
- DynamoDB - Batch Retrieve
- DynamoDB - Batch Writing
- DynamoDB - Delete Items
- DynamoDB - Update Items
- DynamoDB - Getting Items
- DynamoDB - Creating Items
- DynamoDB - API Interface
- DynamoDB - Delete Table
- DynamoDB - Query Table
- DynamoDB - Load Table
- DynamoDB - Create Table
- DynamoDB - Data Types
- DynamoDB - Operations Tools
- DynamoDB - Environment
- DynamoDB - Basic Concepts
- DynamoDB - Overview
- DynamoDB - Home
DynamoDB Useful Resources
Selected Reading
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
选读
DynamoDB - Create Table
Creating a table generally consists of spawning the table, naming it, estabpshing its primary key attributes, and setting attribute data types.
Utipze the GUI Console, Java, or another option to perform these tasks.
Create Table using the GUI Console
Create a table by accessing the console at
. Then choose the “Create Table” option.Our example generates a table populated with product information, with products of unique attributes identified by an ID number (numeric attribute). In the Create Table screen, enter the table name within the table name field; enter the primary key (ID) within the partition key field; and enter “Number” for the data type.
After entering all information, select Create.
Create Table using Java
Use Java to create the same table. Its primary key consists of the following two attributes −
ID − Use a partition key, and the ScalarAttributeType N, meaning number.
Nomenclature − Use a sort key, and the ScalarAttributeType S, meaning string.
Java uses the createTable method to generate a table; and within the call, table name, primary key attributes, and attribute data types are specified.
You can review the following example −
import java.util.Arrays; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBCpent; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType; pubpc class ProductsCreateTable { pubpc static void main(String[] args) throws Exception { AmazonDynamoDBCpent cpent = new AmazonDynamoDBCpent() .withEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(cpent); String tableName = "Products"; try { System.out.println("Creating the table, wait..."); Table table = dynamoDB.createTable (tableName, Arrays.asList ( new KeySchemaElement("ID", KeyType.HASH), // the partition key // the sort key new KeySchemaElement("Nomenclature", KeyType.RANGE) ), Arrays.asList ( new AttributeDefinition("ID", ScalarAttributeType.N), new AttributeDefinition("Nomenclature", ScalarAttributeType.S) ), new ProvisionedThroughput(10L, 10L) ); table.waitForActive(); System.out.println("Table created successfully. Status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Cannot create the table: "); System.err.println(e.getMessage()); } } }
In the above example, note the endpoint: .withEndpoint.
It indicates the use of a local install by using the localhost. Also, note the required ProvisionedThroughput parameter, which the local install ignores.
Advertisements