DynamoDB – Load Table

DynamoDB – Load Table ”; Previous Next Loading a table generally consists of creating a source file, ensuring the source file conforms to a syntax compatible with DynamoDB, sending the source file to the destination, and then confirming a successful population. Utilize the GUI console, Java, or another option to perform the task. Load Table using GUI Console Load data using a combination of the command line and console. You can load data in multiple ways, some of which are as follows − The Console The Command Line Code and also Data Pipeline (a feature discussed later in the tutorial) However, for speed, this example uses both the shell and console. First, load the source data into the destination with the following syntax − aws dynamodb batch-write-item -–request-items file://[filename] For example − aws dynamodb batch-write-item -–request-items file://MyProductData.json Verify the success of the operation by accessing the console at − https://console.aws.amazon.com/dynamodb Choose Tables from the navigation pane, and select the destination table from the table list. Select the Items tab to examine the data you used to populate the table. Select Cancel to return to the table list. Load Table using Java Employ Java by first creating a source file. Our source file uses JSON format. Each product has two primary key attributes (ID and Nomenclature) and a JSON map (Stat) − [ { “ID” : … , “Nomenclature” : … , “Stat” : { … } }, { “ID” : … , “Nomenclature” : … , “Stat” : { … } }, … ] You can review the following example − { “ID” : 122, “Nomenclature” : “Particle Blaster 5000”, “Stat” : { “Manufacturer” : “XYZ Inc.”, “sales” : “1M+”, “quantity” : 500, “img_src” : “http://www.xyz.com/manuals/particleblaster5000.jpg”, “description” : “A laser cutter used in plastic manufacturing.” } } The next step is to place the file in the directory used by your application. Java primarily uses the putItem and path methods to perform the load. You can review the following code example for processing a file and loading it − import java.io.File; import java.util.Iterator; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.Table; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.ObjectNode; public class ProductsLoadData { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint(“http://localhost:8000”); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable(“Products”); JsonParser parser = new JsonFactory() .createParser(new File(“productinfo.json”)); JsonNode rootNode = new ObjectMapper().readTree(parser); Iterator<JsonNode> iter = rootNode.iterator(); ObjectNode currentNode; while (iter.hasNext()) { currentNode = (ObjectNode) iter.next(); int ID = currentNode.path(“ID”).asInt(); String Nomenclature = currentNode.path(“Nomenclature”).asText(); try { table.putItem(new Item() .withPrimaryKey(“ID”, ID, “Nomenclature”, Nomenclature) .withJSON(“Stat”, currentNode.path(“Stat”).toString())); System.out.println(“Successful load: ” + ID + ” ” + Nomenclature); } catch (Exception e) { System.err.println(“Cannot add product: ” + ID + ” ” + Nomenclature); System.err.println(e.getMessage()); break; } } parser.close(); } } Print Page Previous Next Advertisements ”;

DynamoDB – Overview

DynamoDB – Overview ”; Previous Next DynamoDB allows users to create databases capable of storing and retrieving any amount of data, and serving any amount of traffic. It automatically distributes data and traffic over servers to dynamically manage each customer”s requests, and also maintains fast performance. DynamoDB vs. RDBMS DynamoDB uses a NoSQL model, which means it uses a non-relational system. The following table highlights the differences between DynamoDB and RDBMS − Common Tasks RDBMS DynamoDB Connect to the Source It uses a persistent connection and SQL commands. It uses HTTP requests and API operations Create a Table Its fundamental structures are tables, and must be defined. It only uses primary keys, and no schema on creation. It uses various data sources. Get Table Info All table info remains accessible Only primary keys are revealed. Load Table Data It uses rows made of columns. In tables, it uses items made of attributes Read Table Data It uses SELECT statements and filtering statements. It uses GetItem, Query, and Scan. Manage Indexes It uses standard indexes created through SQL statements. Modifications to it occur automatically on table changes. It uses a secondary index to achieve the same function. It requires specifications (partition key and sort key). Modify Table Data It uses an UPDATE statement. It uses an UpdateItem operation. Delete Table Data It uses a DELETE statement. It uses a DeleteItem operation. Delete a Table It uses a DROP TABLE statement. It uses a DeleteTable operation. Advantages The two main advantages of DynamoDB are scalability and flexibility. It does not force the use of a particular data source and structure, allowing users to work with virtually anything, but in a uniform way. Its design also supports a wide range of use from lighter tasks and operations to demanding enterprise functionality. It also allows simple use of multiple languages: Ruby, Java, Python, C#, Erlang, PHP, and Perl. Limitations DynamoDB does suffer from certain limitations, however, these limitations do not necessarily create huge problems or hinder solid development. You can review them from the following points − Capacity Unit Sizes − A read capacity unit is a single consistent read per second for items no larger than 4KB. A write capacity unit is a single write per second for items no bigger than 1KB. Provisioned Throughput Min/Max − All tables and global secondary indices have a minimum of one read and one write capacity unit. Maximums depend on region. In the US, 40K read and write remains the cap per table (80K per account), and other regions have a cap of 10K per table with a 20K account cap. Provisioned Throughput Increase and Decrease − You can increase this as often as needed, but decreases remain limited to no more than four times daily per table. Table Size and Quantity Per Account − Table sizes have no limits, but accounts have a 256 table limit unless you request a higher cap. Secondary Indexes Per Table − Five local and five global are permitted. Projected Secondary Index Attributes Per Table − DynamoDB allows 20 attributes. Partition Key Length and Values − Their minimum length sits at 1 byte, and maximum at 2048 bytes, however, DynamoDB places no limit on values. Sort Key Length and Values − Its minimum length stands at 1 byte, and maximum at 1024 bytes, with no limit for values unless its table uses a local secondary index. Table and Secondary Index Names − Names must conform to a minimum of 3 characters in length, and a maximum of 255. They use the following characters: AZ, a-z, 0-9, “_”, “-”, and “.”. Attribute Names − One character remains the minimum, and 64KB the maximum, with exceptions for keys and certain attributes. Reserved Words − DynamoDB does not prevent the use of reserved words as names. Expression Length − Expression strings have a 4KB limit. Attribute expressions have a 255-byte limit. Substitution variables of an expression have a 2MB limit. Print Page Previous Next Advertisements ”;

DynamoDB – Creating Items

DynamoDB – Creating Items ”; Previous Next Creating an item in DynamoDB consists primarily of item and attribute specification, and the option of specifying conditions. Each item exists as a set of attributes, with each attribute named and assigned a value of a certain type. Value types include scalar, document, or set. Items carry a 400KB size limit, with the possibility of any amount of attributes capable of fitting within that limit. Name and value sizes (binary and UTF-8 lengths) determine item size. Using short attribute names aids in minimizing item size. Note − You must specify all primary key attributes, with primary keys only requiring the partition key; and composite keys requiring both the partition and sort key. Also, remember tables possess no predefined schema. You can store dramatically different datasets in one table. Use the GUI console, Java, or another tool to perform this task. How to Create an Item Using the GUI Console? Navigate to the console. In the navigation pane on the left side, select Tables. Choose the table name for use as the destination, and then select the Items tab as shown in the following screenshot. Select Create Item. The Create Item screen provides an interface for entering the required attribute values. Any secondary indices must also be entered. If you require more attributes, select the action menu on the left of the Message. Then select Append, and the desired data type. After entering all essential information, select Save to add the item. How to Use Java in Item Creation? Using Java in item creation operations consists of creating a DynamoDB class instance, Table class instance, Item class instance, and specifying the primary key and attributes of the item you will create. Then add your new item with the putItem method. Example DynamoDB dynamoDB = new DynamoDB (new AmazonDynamoDBClient( new ProfileCredentialsProvider())); Table table = dynamoDB.getTable(“ProductList”); // Spawn a related items list List<Number> RELItems = new ArrayList<Number>(); RELItems.add(123); RELItems.add(456); RELItems.add(789); //Spawn a product picture map Map<String, String> photos = new HashMap<String, String>(); photos.put(“Anterior”, “http://xyz.com/products/101_front.jpg”); photos.put(“Posterior”, “http://xyz.com/products/101_back.jpg”); photos.put(“Lateral”, “http://xyz.com/products/101_LFTside.jpg”); //Spawn a product review map Map<String, List<String>> prodReviews = new HashMap<String, List<String>>(); List<String> fiveStarRVW = new ArrayList<String>(); fiveStarRVW.add(“Shocking high performance.”); fiveStarRVW.add(“Unparalleled in its market.”); prodReviews.put(“5 Star”, fiveStarRVW); List<String> oneStarRVW = new ArrayList<String>(); oneStarRVW.add(“The worst offering in its market.”); prodReviews.put(“1 Star”, oneStarRVW); // Generate the item Item item = new Item() .withPrimaryKey(“Id”, 101) .withString(“Nomenclature”, “PolyBlaster 101”) .withString(“Description”, “101 description”) .withString(“Category”, “Hybrid Power Polymer Cutter”) .withString(“Make”, “Brand – XYZ”) .withNumber(“Price”, 50000) .withString(“ProductCategory”, “Laser Cutter”) .withBoolean(“Availability”, true) .withNull(“Qty”) .withList(“ItemsRelated”, RELItems) .withMap(“Images”, photos) .withMap(“Reviews”, prodReviews); // Add item to the table PutItemOutcome outcome = table.putItem(item); You can also look at the following larger example. Note − The following sample may assume a previously created data source. Before attempting to execute, acquire supporting libraries and create necessary data sources (tables with required characteristics, or other referenced sources). The following sample also uses Eclipse IDE, an AWS credentials file, and the AWS Toolkit within an Eclipse AWS Java Project. package com.amazonaws.codesamples.document; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome; import com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec; import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec; import com.amazonaws.services.dynamodbv2.document.utils.NameMap; import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; import com.amazonaws.services.dynamodbv2.model.ReturnValue; public class CreateItemOpSample { static DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient ( new ProfileCredentialsProvider())); static String tblName = “ProductList”; public static void main(String[] args) throws IOException { createItems(); retrieveItem(); // Execute updates updateMultipleAttributes(); updateAddNewAttribute(); updateExistingAttributeConditionally(); // Item deletion deleteItem(); } private static void createItems() { Table table = dynamoDB.getTable(tblName); try { Item item = new Item() .withPrimaryKey(“ID”, 303) .withString(“Nomenclature”, “Polymer Blaster 4000”) .withStringSet( “Manufacturers”, new HashSet<String>(Arrays.asList(“XYZ Inc.”, “LMNOP Inc.”))) .withNumber(“Price”, 50000) .withBoolean(“InProduction”, true) .withString(“Category”, “Laser Cutter”); table.putItem(item); item = new Item() .withPrimaryKey(“ID”, 313) .withString(“Nomenclature”, “Agitatatron 2000”) .withStringSet( “Manufacturers”, new HashSet<String>(Arrays.asList(“XYZ Inc,”, “CDE Inc.”))) .withNumber(“Price”, 40000) .withBoolean(“InProduction”, true) .withString(“Category”, “Agitator”); table.putItem(item); } catch (Exception e) { System.err.println(“Cannot create items.”); System.err.println(e.getMessage()); } } } Print Page Previous Next Advertisements ”;

DynamoDB – Data Types

DynamoDB – Data Types ”; Previous Next Data types supported by DynamoDB include those specific to attributes, actions, and your coding language of choice. Attribute Data Types DynamoDB supports a large set of data types for table attributes. Each data type falls into one of the three following categories − Scalar − These types represent a single value, and include number, string, binary, Boolean, and null. Document − These types represent a complex structure possessing nested attributes, and include lists and maps. Set − These types represent multiple scalars, and include string sets, number sets, and binary sets. Remember DynamoDB as a schemaless, NoSQL database that does not need attribute or data type definitions when creating a table. It only requires a primary key attribute data types in contrast to RDBMS, which require column data types on table creation. Scalars Numbers − They are limited to 38 digits, and are either positive, negative, or zero. String − They are Unicode using UTF-8, with a minimum length of >0 and maximum of 400KB. Binary − They store any binary data, e.g., encrypted data, images, and compressed text. DynamoDB views its bytes as unsigned. Boolean − They store true or false. Null − They represent an unknown or undefined state. Document List − It stores ordered value collections, and uses square ([…]) brackets. Map − It stores unordered name-value pair collections, and uses curly ({…}) braces. Set Sets must contain elements of the same type whether number, string, or binary. The only limits placed on sets consist of the 400KB item size limit, and each element being unique. Action Data Types DynamoDB API holds various data types used by actions. You can review a selection of the following key types − AttributeDefinition − It represents key table and index schema. Capacity − It represents the quantity of throughput consumed by a table or index. CreateGlobalSecondaryIndexAction − It represents a new global secondary index added to a table. LocalSecondaryIndex − It represents local secondary index properties. ProvisionedThroughput − It represents the provisioned throughput for an index or table. PutRequest − It represents PutItem requests. TableDescription − It represents table properties. Supported Java Datatypes DynamoDB provides support for primitive data types, Set collections, and arbitrary types for Java. Print Page Previous Next Advertisements ”;

DynamoDB – Delete Table

DynamoDB – Delete Table ”; Previous Next In this chapter, we will discuss regarding how we can delete a table and also the different ways of deleting a table. Table deletion is a simple operation requiring little more than the table name. Utilize the GUI console, Java, or any other option to perform this task. Delete Table using the GUI Console Perform a delete operation by first accessing the console at − https://console.aws.amazon.com/dynamodb. Choose Tables from the navigation pane, and choose the table desired for deletion from the table list as shown in the following screeenshot. Finally, select Delete Table. After choosing Delete Table, a confirmation appears. Your table is then deleted. Delete Table using Java Use the delete method to remove a table. An example is given below to explain the concept better. import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; public class ProductsDeleteTable { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint(“http://localhost:8000”); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable(“Products”); try { System.out.println(“Performing table delete, wait…”); table.delete(); table.waitForDelete(); System.out.print(“Table successfully deleted.”); } catch (Exception e) { System.err.println(“Cannot perform table delete: “); System.err.println(e.getMessage()); } } } Print Page Previous Next Advertisements ”;

DynamoDB – Basic Concepts

DynamoDB – Basic Concepts ”; Previous Next Before using DynamoDB, you must familiarize yourself with its basic components and ecosystem. In the DynamoDB ecosystem, you work with tables, attributes, and items. A table holds sets of items, and items hold sets of attributes. An attribute is a fundamental element of data requiring no further decomposition, i.e., a field. Primary Key The Primary Keys serve as the means of unique identification for table items, and secondary indexes provide query flexibility. DynamoDB streams record events by modifying the table data. The Table Creation requires not only setting a name, but also the primary key; which identifies table items. No two items share a key. DynamoDB uses two types of primary keys − Partition Key − This simple primary key consists of a single attribute referred to as the “partition key.” Internally, DynamoDB uses the key value as input for a hash function to determine storage. Partition Key and Sort Key − This key, known as the “Composite Primary Key”, consists of two attributes. The partition key and The sort key. DynamoDB applies the first attribute to a hash function, and stores items with the same partition key together; with their order determined by the sort key. Items can share partition keys, but not sort keys. The Primary Key attributes only allow scalar (single) values; and string, number, or binary data types. The non-key attributes do not have these constraints. Secondary Indexes These indexes allow you to query table data with an alternate key. Though DynamoDB does not force their use, they optimize querying. DynamoDB uses two types of secondary indexes − Global Secondary Index − This index possesses partition and sort keys, which can differ from table keys. Local Secondary Index − This index possesses a partition key identical to the table, however, its sort key differs. API The API operations offered by DynamoDB include those of the control plane, data plane (e.g., creation, reading, updating, and deleting), and streams. In control plane operations, you create and manage tables with the following tools − CreateTable DescribeTable ListTables UpdateTable DeleteTable In the data plane, you perform CRUD operations with the following tools − Create Read Update Delete PutItem BatchWriteItem GetItem BatchGetItem Query Scan UpdateItem DeleteItem BatchWriteItem The stream operations control table streams. You can review the following stream tools − ListStreams DescribeStream GetShardIterator GetRecords Provisioned Throughput In table creation, you specify provisioned throughput, which reserves resources for reads and writes. You use capacity units to measure and set throughput. When applications exceed the set throughput, requests fail. The DynamoDB GUI console allows monitoring of set and used throughput for better and dynamic provisioning. Read Consistency DynamoDB uses eventually consistent and strongly consistent reads to support dynamic application needs. Eventually consistent reads do not always deliver current data. The strongly consistent reads always deliver current data (with the exception of equipment failure or network problems). Eventually consistent reads serve as the default setting, requiring a setting of true in the ConsistentRead parameter to change it. Partitions DynamoDB uses partitions for data storage. These storage allocations for tables have SSD backing and automatically replicate across zones. DynamoDB manages all the partition tasks, requiring no user involvement. In table creation, the table enters the CREATING state, which allocates partitions. When it reaches ACTIVE state, you can perform operations. The system alters partitions when its capacity reaches maximum or when you change throughput. Print Page Previous Next Advertisements ”;

DynamoDB – Query Table

DynamoDB – Query Table ”; Previous Next Querying a table primarily requires selecting a table, specifying a partition key, and executing the query; with the options of using secondary indexes and performing deeper filtering through scan operations. Utilize the GUI Console, Java, or another option to perform the task. Query Table using the GUI Console Perform some simple queries using the previously created tables. First, open the console at https://console.aws.amazon.com/dynamodb Choose Tables from the navigation pane and select Reply from the table list. Then select the Items tab to see the loaded data. Select the data filtering link (“Scan: [Table] Reply”) beneath the Create Item button. In the filtering screen, select Query for the operation. Enter the appropriate partition key value, and click Start. The Reply table then returns matching items. Query Table using Java Use the query method in Java to perform data retrieval operations. It requires specifying the partition key value, with the sort key as optional. Code a Java query by first creating a querySpec object describing parameters. Then pass the object to the query method. We use the partition key from the previous examples. You can review the following example − import java.util.HashMap; import java.util.Iterator; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.ItemCollection; import com.amazonaws.services.dynamodbv2.document.QueryOutcome; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; import com.amazonaws.services.dynamodbv2.document.utils.NameMap; public class ProductsQuery { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint(“http://localhost:8000”); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable(“Products”); HashMap<String, String> nameMap = new HashMap<String, String>(); nameMap.put(“#ID”, “ID”); HashMap<String, Object> valueMap = new HashMap<String, Object>(); valueMap.put(“:xxx”, 122); QuerySpec querySpec = new QuerySpec() .withKeyConditionExpression(“#ID = :xxx”) .withNameMap(new NameMap().with(“#ID”, “ID”)) .withValueMap(valueMap); ItemCollection<QueryOutcome> items = null; Iterator<Item> iterator = null; Item item = null; try { System.out.println(“Product with the ID 122”); items = table.query(querySpec); iterator = items.iterator(); while (iterator.hasNext()) { item = iterator.next(); System.out.println(item.getNumber(“ID”) + “: ” + item.getString(“Nomenclature”)); } } catch (Exception e) { System.err.println(“Cannot find products with the ID number 122”); System.err.println(e.getMessage()); } } } Note that the query uses the partition key, however, secondary indexes provide another option for queries. Their flexibility allows querying of non-key attributes, a topic which will be discussed later in this tutorial. The scan method also supports retrieval operations by gathering all the table data. The optional .withFilterExpression prevents items outside of specified criteria from appearing in results. Later in this tutorial, we will discuss scanning in detail. Now, take a look at the following example − import java.util.Iterator; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.ItemCollection; import com.amazonaws.services.dynamodbv2.document.ScanOutcome; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; import com.amazonaws.services.dynamodbv2.document.utils.NameMap; import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; public class ProductsScan { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint(“http://localhost:8000”); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable(“Products”); ScanSpec scanSpec = new ScanSpec() .withProjectionExpression(“#ID, Nomenclature , stat.sales”) .withFilterExpression(“#ID between :start_id and :end_id”) .withNameMap(new NameMap().with(“#ID”, “ID”)) .withValueMap(new ValueMap().withNumber(“:start_id”, 120) .withNumber(“:end_id”, 129)); try { ItemCollection<ScanOutcome> items = table.scan(scanSpec); Iterator<Item> iter = items.iterator(); while (iter.hasNext()) { Item item = iter.next(); System.out.println(item.toString()); } } catch (Exception e) { System.err.println(“Cannot perform a table scan:”); System.err.println(e.getMessage()); } } } Print Page Previous Next Advertisements ”;

DynamoDB – Create Table

DynamoDB – Create Table ”; Previous Next Creating a table generally consists of spawning the table, naming it, establishing its primary key attributes, and setting attribute data types. Utilize 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 https://console.aws.amazon.com/dynamodb. 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.AmazonDynamoDBClient; 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; public class ProductsCreateTable { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint(“http://localhost:8000”); DynamoDB dynamoDB = new DynamoDB(client); 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. Print Page Previous Next Advertisements ”;