
Document interface
This interface enables you to do Create, Read, Update, and Delete (CRUD) operations on tables and indexes. The datatype will be implied with data from this interface and you do not need to specify it.
The AWS SDKs for Java, Node.js, JavaScript, and .NET provides support for document interfaces.
The following example uses the Java language for the document interface in AWS SDKs. Here you can use the Eclipse IDE for the example.
In this Java program, we will create a table object from the Movies table, pass the movie name as attribute, and print the movie release year.
We have to import a few classes. DynamoDB is the entry point to use this library in your class. GetItemOutcomeis is used to get items from the DynamoDB table. Table is used to get table details:
static AmazonDynamoDB client;
The preceding code will create the client instance. You have to assign the credentials and region to this instance:
String tableName = "Movies";
DynamoDB docClient = new DynamoDB(client);
Table movieTable = docClient.getTable(tableName);
DynamoDB will create the instance of docClient by passing the client instance. It is the entry point for the document interface library. This docClient instance will get the table details by passing the tableName and assign it to the movieTable instance:
GetItemOutcome outcome = movieTable.getItemOutcome("name","Airplane");
int yearObj = outcome.getItem().getInt("year");
System.out.println("The movie was released in " + yearObj);
GetItemOutcome will create an outcome instance from movieTable by passing the name as key and movie name as parameter. It will retrieve the item year from the outcome object and store it into the yearObj object and print it:
