Reader small image

You're reading from  DynamoDB Applied Design Patterns

Product typeBook
Published inSep 2014
Publisher
ISBN-139781783551897
Edition1st Edition
Right arrow

Chapter 3. Tools and Libraries of AWS DynamoDB

We have understood the strength of the Eclipse plugin in the previous chapter on interfaces. We have seen a few of the basic operations using three interfaces. But along with those interfaces, DynamoDB supports lots of tools and libraries. In this chapter, we will see one such tool that is used along with the Eclipse IDE. We will mostly perform DynamoDB operations using the Java SDK. In this chapter, we will cover the following topics:

  • Creating an SDK project

  • SDK operations

  • DynamoDB Local

We can easily create tables, indexes, attributes, and items. After doing all of these offline, we can commit or save to AWS DynamoDB. This is the use of DynamoDB Local.

If we need to insert event data (which is available as a CSV file) into DynamoDB, are we comfortable looking at the CSV file manually and creating one item for every event and finally put it into the table? Is it possible to perform the operation if the item size of the CSV file goes beyond a million...

Creating your first SDK project


If we have already installed the Eclipse plugin and are able to see the credentials file created correctly, then we are ready to fly on the SDK plane. Here's how:

  1. Clicking on the AWS toolkit for the Eclipse icon will provide us with the option to create a new AWS project as shown:

  2. Here we need to select New AWS Java Project.... Clicking on this option will open the following window. Clicking on this option for the first time will bring up a few sample codes from AWS and will ask whether we want these sample codes to be part of the project.

  3. It is recommended that you check the Amazon DynamoDB Sample checkbox the first time, to understand the syntax of DynamoDB table operations.

  4. Once done, select the AWS account that is already configured, or configure a new AWS account.

  5. Click on the Next button to proceed.

  6. Clicking on the Next button will create a new project with the name specified in the previous window. The project structure is shown in the next screenshot.

  7. The...

Java SDK operations


There are eight user-defined private functions that are being invoked in the following code. We will see each and every function in detail:

public class AwsSdkDemo {

  static AmazonDynamoDBClient client;
  public static void main(String[] args) {
    try {

      initializeCredentials();
      String tableName = "Tbl_Book";

      if (Tables.doesTableExist(client, tableName)) {
        System.out.println("Table " + tableName + " already EXISTS");
      } 
      else {
        ArrayList<AttributeDefinition> attributeDefinitions = getTableAttributes();
        ArrayList<KeySchemaElement> keySchemaElements = getTableKeySchema();
        LocalSecondaryIndex localSecondaryIndex = getLocalSecondaryIndex();
        ArrayList<LocalSecondaryIndex> localSecondaryIndexes = newArrayList<LocalSecondaryIndex>();
        localSecondaryIndexes.add(localSecondaryIndex);
        GlobalSecondaryIndex globalSecondaryIndex = getGlobalSecondaryIndex();
        ProvisionedThroughput...

DynamoDB Local


DynamoDB Local is a local client-side database that emulates the DynamoDB database in our local system. This is pretty helpful while developing an application that uses DynamoDB as the backend. Every time after writing a module, in order to test whether the code works fine, we need to connect to Amazon and run it. This will consume a lot of bandwidth and a few dollars. To avoid this we can make use of DynamoDB Local and test the code locally. Once the testing is done we can then make our application use the AWS DynamoDB service. You need to perform only three actions for this, which are as follows:

  1. Download DynamoDB Local from http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.

  2. Start the DynamoDB Local service (should have JRE 6 or later).

  3. Point the code to use the DynamoDB Local port.

We don't need to discuss more about how to download a file from the Internet. So, let's go directly to step 2. The downloaded file might be a zipped one (tar.gz or zip...

Summary


In this chapter, we have learned how to create an SDK project and how to perform SDK operations. Moreover, we have seen how DynamoDB Local works at client side. From DynamoDB Local we can understand the behavior of the DynamoDB database at the local end.

Indexes are very important for any database. So in the next chapter, we will learn what secondary indexes are, how to use secondary indexes with DynamoDB, and how they work effectively in DynamoDB.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
DynamoDB Applied Design Patterns
Published in: Sep 2014Publisher: ISBN-13: 9781783551897
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime