Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
DynamoDB Cookbook
DynamoDB Cookbook

DynamoDB Cookbook: Over 90 hands-on recipes to design Internet scalable web and mobile applications with Amazon DynamoDB

eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

DynamoDB Cookbook

Chapter 2. Operating with DynamoDB Tables

In this chapter, we will cover the following topics:

  • Creating a table using the AWS SDK for Java
  • Creating a table using the AWS SDK for .Net
  • Creating a table using the AWS SDK for PHP
  • Updating a table using the AWS SDK for Java
  • Updating a table using the AWS SDK for .Net
  • Updating a table using the AWS SDK for PHP
  • Listing tables using the AWS SDK for Java
  • Listing tables using the AWS SDK for .Net
  • Listing tables using the AWS SDK for PHP
  • Deleting a table using the AWS SDK for Java
  • Deleting a table using the AWS SDK for .Net
  • Deleting a table using the AWS SDK for PHP

Introduction

In the previous chapter, we discussed how to perform various DynamoDB operations using the console. In this chapter, we will focus on how to use the SDK provided by Amazon to perform operations. Amazon has provided SDKs in various programming languages, out of which we are going to see operations in Java, .Net, and PHP. So, get ready to get your hands dirty with the code!

Creating a table using the AWS SDK for Java

Let's start with creating a table in DynamoDB using SDKs provided by Amazon.

Getting ready

To program various DynamoDB table operations, you can use the IDE of your choice, for example, Eclipse, NetBeans, Visual Studio, and so on. Here, we will be using the Eclipse IDE. In the previous chapter, we have already seen how to download and set up the Eclipse IDE.

How to do it…

Let's first see how to create a table in DynamoDB using the AWS SDK for Java.

You can create a Maven project and add the AWS SDK Maven dependency. The latest version available can be found at http://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk/.

Here, I will be using Version 1.9.30, and its POM looks like this:

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk</artifactId>
  <version>1.9.30</version>
</dependency>

Here are the steps to create a table using the AWS SDK for Java:

  1. Create an...

Creating a table using the AWS SDK for .Net

Now, let's understand how to create a DynamoDB table using the AWS SDK for .Net.

Getting ready

You can use an IDE, such as Visual Studio to code these recipes. You can refer to the AWS documentation on how to set up your workstation at http://aws.amazon.com/sdk-for-net/.

How to do it…

Let's start with creating a table called productTableNet:

  1. Instantiate the CreateTable request specifying AttributeDefinition and KeySchema. We will create the table having both the HASH and RANGE Keys. We will set the provisioned read and write capacity units to be one:
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTableNet";
    var request=new CreateTableRequest{
      AttributeDefinitions=newList<AttributeDefinition>(){
        newAttributeDefinition{
          AttributeName="id", AttributeType="N"
        },
        newAttributeDefinition{
          AttributeName="type", AttributeType="S...

Creating a table using the AWS SDK for PHP

Now, let's understand how to create a DynamoDB table using the AWS SDK for PHP.

Getting ready…

You can use the IDE of your choice to code these recipes.

How to do it…

Let's start with creating a table called productTablePHP:

  1. Instantiate the DynamoDB client for PHP. Specify the AWS region in which you wish to create the table in:
    $client = DynamoDbClient::factory(array(
        'profile' => 'default',
        'region' => 'us-west-1'  
    ));
  2. Invoke the createTable method by specifying the details, such as the table name, hash and range keys, and provisioned capacity units. Here, we will create a table with the primary key as the composite hash and range keys:
    $result = $client->createTable(array(
        'TableName' => $tableName,
        'AttributeDefinitions' => array(
            array(
                'AttributeName' => 'id',
                'AttributeType...

Updating a table using the AWS SDK for Java

Now, let's understand how to update a DynamoDB table using the AWS SDK for Java.

Getting ready…

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to update the already created DynamoDB table. Here, we will update the read and write capacity units:

  1. Create an instance of the Table class and initiate it by calling the getTable method:
    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
    client.setRegion(Region.getRegion(Regions.US_EAST_1));
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("productTableJava");
  2. Now, create an instance of the provisioned throughput, and set the read and write capacity units. Earlier, we set the read and write capacity units to one, and now we will update it to two:
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L).withWriteCapacityUnits...

Updating a table using the AWS SDK for .Net

Now, let's understand how to update a DynamoDB table using the AWS SDK for .Net.

Getting ready

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to update the provisioned capacity of the already created table using the AWS SDK for .Net:

  1. Create an update table request and provide the new read and write capacity units:
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTableNet";
    var request=new UpdateTableRequest(){
      TableName=tableName,
      ProvisionedThroughput = new ProvisionedThroughput(){
        ReadCapacityUnits=2,
          WriteCapacityUnits=2
      }
    };
  2. Invoke the updateTable method from the DynamoDB client to update the table with the provided capacity units:
    var response = client.UpdateTable(request);
  3. It takes some time for DynamoDB to make the changes effective. So, it's always a best practice to wait until the table becomes active again...

Introduction


In the previous chapter, we discussed how to perform various DynamoDB operations using the console. In this chapter, we will focus on how to use the SDK provided by Amazon to perform operations. Amazon has provided SDKs in various programming languages, out of which we are going to see operations in Java, .Net, and PHP. So, get ready to get your hands dirty with the code!

Creating a table using the AWS SDK for Java


Let's start with creating a table in DynamoDB using SDKs provided by Amazon.

Getting ready

To program various DynamoDB table operations, you can use the IDE of your choice, for example, Eclipse, NetBeans, Visual Studio, and so on. Here, we will be using the Eclipse IDE. In the previous chapter, we have already seen how to download and set up the Eclipse IDE.

How to do it…

Let's first see how to create a table in DynamoDB using the AWS SDK for Java.

You can create a Maven project and add the AWS SDK Maven dependency. The latest version available can be found at http://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk/.

Here, I will be using Version 1.9.30, and its POM looks like this:

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk</artifactId>
  <version>1.9.30</version>
</dependency>

Here are the steps to create a table using the AWS SDK for Java:

  1. Create an instance of the DynamoDB...

Creating a table using the AWS SDK for .Net


Now, let's understand how to create a DynamoDB table using the AWS SDK for .Net.

Getting ready

You can use an IDE, such as Visual Studio to code these recipes. You can refer to the AWS documentation on how to set up your workstation at http://aws.amazon.com/sdk-for-net/.

How to do it…

Let's start with creating a table called productTableNet:

  1. Instantiate the CreateTable request specifying AttributeDefinition and KeySchema. We will create the table having both the HASH and RANGE Keys. We will set the provisioned read and write capacity units to be one:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTableNet";
    var request=new CreateTableRequest{
      AttributeDefinitions=newList<AttributeDefinition>(){
        newAttributeDefinition{
          AttributeName="id", AttributeType="N"
        },
        newAttributeDefinition{
          AttributeName="type", AttributeType="S"
        }
      },
      KeySchema=newList<KeySchemaElement>{
        newKeySchemaElement...

Creating a table using the AWS SDK for PHP


Now, let's understand how to create a DynamoDB table using the AWS SDK for PHP.

Getting ready…

You can use the IDE of your choice to code these recipes.

How to do it…

Let's start with creating a table called productTablePHP:

  1. Instantiate the DynamoDB client for PHP. Specify the AWS region in which you wish to create the table in:

    $client = DynamoDbClient::factory(array(
        'profile' => 'default',
        'region' => 'us-west-1'  
    ));
  2. Invoke the createTable method by specifying the details, such as the table name, hash and range keys, and provisioned capacity units. Here, we will create a table with the primary key as the composite hash and range keys:

    $result = $client->createTable(array(
        'TableName' => $tableName,
        'AttributeDefinitions' => array(
            array(
                'AttributeName' => 'id',
                'AttributeType' => 'N'
            ),
            array(
                'AttributeName' => 'type',
                'AttributeType' ...

Updating a table using the AWS SDK for Java


Now, let's understand how to update a DynamoDB table using the AWS SDK for Java.

Getting ready…

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to update the already created DynamoDB table. Here, we will update the read and write capacity units:

  1. Create an instance of the Table class and initiate it by calling the getTable method:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
    client.setRegion(Region.getRegion(Regions.US_EAST_1));
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("productTableJava");
  2. Now, create an instance of the provisioned throughput, and set the read and write capacity units. Earlier, we set the read and write capacity units to one, and now we will update it to two:

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L).withWriteCapacityUnits(2L);
  3. Now, invoke the updateTable...

Updating a table using the AWS SDK for .Net


Now, let's understand how to update a DynamoDB table using the AWS SDK for .Net.

Getting ready

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to update the provisioned capacity of the already created table using the AWS SDK for .Net:

  1. Create an update table request and provide the new read and write capacity units:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTableNet";
    var request=new UpdateTableRequest(){
      TableName=tableName,
      ProvisionedThroughput = new ProvisionedThroughput(){
        ReadCapacityUnits=2,
          WriteCapacityUnits=2
      }
    };
  2. Invoke the updateTable method from the DynamoDB client to update the table with the provided capacity units:

    var response = client.UpdateTable(request);
  3. It takes some time for DynamoDB to make the changes effective. So, it's always a best practice to wait until the table becomes active again. By default, the AWS SDK for...

Updating a table using the AWS SDK for PHP


Now, let's understand how to update a DynamoDB table using the AWS SDK for PHP.

Getting ready

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to update the read and write capacity units for an already created table:

  1. Create an instance of the DynamoDB client and invoke the updateTable method, providing the details of the new provisioned throughout capacity units. Here, we will update the read and write capacity units to two:

    $tableName = 'productTablePHP';
    $result = $client->updateTable(array(
        'TableName' => $tableName,
        'ProvisionedThroughput'    => array(
            'ReadCapacityUnits'    => 2,        
            'WriteCapacityUnits' => 2          
        )
    ));
  2. DynamoDB takes some time to make the changes effective. So, it's a best practice to wait until the table gets effective again:

    $client->waitUntilTableExists(array('TableName' => $tableName));

How it works…

Once we invoke...

Left arrow icon Right arrow icon

Description

AWS DynamoDB is an excellent example of a production-ready NoSQL database. In recent years, DynamoDB has been able to attract many customers because of its features like high-availability, reliability and infinite scalability. DynamoDB can be easily integrated with massive data crunching tools like Hadoop /EMR, which is an essential part of this data-driven world and hence it is widely accepted. The cost and time-efficient design makes DynamoDB stand out amongst its peers. The design of DynamoDB is so neat and clean that it has inspired many NoSQL databases to simply follow it. This book will get your hands on some engineering best practices DynamoDB engineers use, which can be used in your day-to-day life to build robust and scalable applications. You will start by operating with DynamoDB tables and learn to manipulate items and manage indexes. You will also discover how to easily integrate applications with other AWS services like EMR, S3, CloudSearch, RedShift etc. A couple of chapters talk in detail about how to use DynamoDB as a backend database and hosting it on AWS ElasticBean. This book will also focus on security measures of DynamoDB as well by providing techniques on data encryption, masking etc. By the end of the book you’ll be adroit in designing web and mobile applications using DynamoDB and host it on cloud.

Who is this book for?

This book is intended for those who have a basic understanding of AWS services and want to take their knowledge to the next level by getting their hands dirty with coding recipes in DynamoDB.

What you will learn

  • Design DynamoDB tables to achieve high read and write throughput
  • Discover best practices like caching, exponential backoffs and autoretries, storing large items in AWS S3, storing compressed data etc.
  • Effectively use DynamoDB Local in order to make your development smooth and cost effective
  • Implement cost effective best practices to reduce the burden of DynamoDB charges
  • Create and maintain secondary indexes to support improved data access
  • Integrate various other AWS services like AWS EMR, AWS CloudSearch, AWS Pipeline etc. with DynamoDB

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 25, 2015
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391096
Category :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 25, 2015
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781784391096
Category :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 145.97
DynamoDB Cookbook
$48.99
DynamoDB Applied Design Patterns
$48.99
Mastering DynamoDB
$47.99
Total $ 145.97 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Taking Your First Steps with DynamoDB Chevron down icon Chevron up icon
2. Operating with DynamoDB Tables Chevron down icon Chevron up icon
3. Manipulating DynamoDB Items Chevron down icon Chevron up icon
4. Managing DynamoDB Indexes Chevron down icon Chevron up icon
5. Exploring Higher Level Programming Interfaces for DynamoDB Chevron down icon Chevron up icon
6. Securing DynamoDB Chevron down icon Chevron up icon
7. DynamoDB Best Practices Chevron down icon Chevron up icon
8. Integrating DynamoDB with other AWS Services Chevron down icon Chevron up icon
9. Developing Web Applications using DynamoDB Chevron down icon Chevron up icon
10. Developing Mobile Applications using DynamoDB Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(8 Ratings)
5 star 50%
4 star 25%
3 star 0%
2 star 12.5%
1 star 12.5%
Filter icon Filter
Top Reviews

Filter reviews by




Kenny Ha Nov 28, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really wished that this book had came out a few years earlier. This excellent NoSQL DynamoDB Cookbook will allow you to gain insights into the next generation of high-availability, reliability and infinite scalability of developing internet & mobile applications. Whether you're a programmer or an architect, if you're looking to design scalable distributed systems, you must check out this book. This book provides a step-by-step instruction on how to create tables and manipulate items. There are examples of best practices and sample codes to help you manage primary key type, hash and range attributes along with global local and secondary indices. In addition, there are integration examples with other advanced AWS services. You can get this book at https://www.packtpub.com/big-data-and-business-intelligence/dynamodb-cookbook. For further technical reading, you can visit http://oneglobalonline.com.
Amazon Verified review Amazon
SuJo Dec 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have a MySQL / MSSQL / MongoDB background for all of my web applications and I wanted to branch out into DynamoDB for performance gains in highly available applications. The book covered everything clearly, how to achieve high read/write throughput while guiding you with best practices. While I just started with the NoSQL databases this one worked fine for my tests, and in a data-driven environment it will certainly out perform my slow MSSQL transactions. Not to mention the per core licence M$ is doing, crazy! I highly recommend this book if you want to get serious about high availability for data demanding applications.
Amazon Verified review Amazon
PJG Dec 01, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As with many cookbooks of this type, the entire thing rests on whether the recipes included are actually of practical use or not. In this case, they most definitely are, and follow a well-arranged and logical order that starts from the basics. The great thing about the recipes is that they reallydo allow the reader to get to grips with a well-featured and highly-performant NoSQL database, and the book really hits the ground running. The chapters include relevant 'best practices' and a very useful later chapter on how to integrate DynamoSB with other AWS services.As with many Packt titles, the book is succinct - just under 200 pages - but this style seems to work much better in cookbook format where very specific examples, that are relatively self-contained, are presented. Recommended for anyone looking to get acquainted with DynamoDB through practical examples.
Amazon Verified review Amazon
ruben Dec 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
AWS DynamoDB is an excellent example of a production-ready NoSQL database. In recent years, DynamoDB has been able to attract many customers because of its features like high-availability, reliability and infinite scalability. DynamoDB can be easily integrated with massive data crunching tools like Hadoop /EMR, which is an essential part of this data-driven world and hence it is widely accepted. The cost and time-efficient design makes DynamoDB stand out amongst its peers. The design of DynamoDB is so neat and clean that it has inspired many NoSQL databases to simply follow it.This is a very complete title, I have used MySQL it is an important book that it helps me to learn other tool to manage Database, it is a useful material
Amazon Verified review Amazon
Neeraj Goel Oct 15, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
As expected
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.