Writing Code for DynamoDB Batch Updates
This tutorial references the code in the aws-connectedcar-dotnet-core repository. If you're new to this course, see the introduction for information about setting up your workstation and getting the sample code.
At this point, you may have noticed when looking at the code for the data services that some include "BatchUpdate" methods. These methods are not called by any of the Lambda code, and therefore are not exposed through any of the APIs. Instead, these methods are in the services to show how you can perform bulk data updates from the command line. As you’ll see later in the labs, there’s a big difference in performance between saving items one by one and using one of these batch updates.
Performing Batch Updates
So, in this final code tutorial for DynamoDB, we’ll quickly step through the code below, to show how to use the BatchWrite client. This method is from the CustomerService class:
With this batch update method, you’re passing in a pre-populated list of customers, as shown on line 102. You’re then instantiating the BatchWrite client on line 108, which is then sequentially populated with translated customers and their associated put operations on line 117. Finally, on line 121, the batch is executed, meaning all the customer items are submitted to DynamoDB and then saved as one operation, rather than one by one. We’ll see in the lab that’s coming next just how much of a performance gain you make by saving items in this way.
This tutorial references the code in the aws-connectedcar-java-core repository. If you're new to this course, see the introduction for information about setting up your workstation and getting the sample code.
At this point, you may have noticed when looking at the code for the data services that some include "batchUpdate" methods. These methods are not called by any of the Lambda code, and therefore are not exposed through any of the APIs. Instead, these methods are in the services to show how you can perform bulk data updates from the command line. As you’ll see later in the labs, there’s a big difference in performance between saving items one by one and using one of these batch updates.
Performing Batch Updates
So, in this final code tutorial for DynamoDB, we’ll quickly step through the code below, to show how to use the BatchWrite client. This method is from the CustomerService class:
With this batch update method, you’re passing in a pre-populated list of customers, as shown on line 142. You’re then instantiating the batch Builder instance on line 148, which is then sequentially populated with translated customers and their associated put operations on line 156. Finally, on lines 159-163 a batch request is constructed, which is executed on line 165, saving all the items as one operation, rather than one by one. We’ll see in the lab that’s coming next just how much of a performance gain you make by saving items in this way.
Next: Using Batch Updates to Populate Data