AWS Security ChangesHomeSearch

AWS amazondynamodb documentation change

Service: amazondynamodb · 2025-07-18 · Documentation low

File: amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.md

Summary

Updated Java code example to use AWS SDK v2, added child shard processing, modernized syntax, and improved error handling. Changed table name to StreamsDemoTable and updated stream record examples with new timestamps/sequence numbers.

Security assessment

The changes primarily involve migrating from AWS SDK v1 to v2 and improving code structure. No explicit security vulnerabilities or security feature additions are mentioned. While SDK v2 has security improvements generally, the diff shows routine modernization rather than addressing a specific security issue.

Diff

diff --git a/amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.md b/amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.md
index 8848ba082..4f8277524 100644
--- a//amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.md
+++ b//amazondynamodb/latest/developerguide/Streams.LowLevel.Walkthrough.md
@@ -23 +23,3 @@ This section contains a Java program that shows DynamoDB Streams in action. The
-  6. Cleans up.
+  6. Fetches child shards and continues reading records.
+
+  7. Cleans up.
@@ -31 +33,2 @@ When you run the program, you will see output similar to the following.
-    Issuing CreateTable request for TestTableForStreams
+    Testing Streams Demo
+    Creating an Amazon DynamoDB table TestTableForStreams with a simple primary key: Id
@@ -43,2 +46 @@ When you run the program, you will see output similar to the following.
-    
-    Shard: {ShardId: shardId-1234567890-...,SequenceNumberRange: {StartingSequenceNumber: 01234567890...,},}
+    Shard: {ShardId: shardId-1234567890-...,SequenceNumberRange: {StartingSequenceNumber: 100002572486797508907,},}
@@ -46,3 +48,3 @@ When you run the program, you will see output similar to the following.
-            ApproximateCreationDateTime: Tue Mar 20 09:50:00 PDT 2018,Keys: {Id={N: 1,}},NewImage: {Message={S: New item!,}, Id={N: 1,}},SequenceNumber: 100000000003218256368,SizeBytes: 24,StreamViewType: NEW_AND_OLD_IMAGES}
-             {ApproximateCreationDateTime: Tue Mar 20 09:50:00 PDT 2018,Keys: {Id={N: 1,}},NewImage: {Message={S: This item has changed,}, Id={N: 1,}},OldImage: {Message={S: New item!,}, Id={N: 1,}},SequenceNumber: 200000000003218256412,SizeBytes: 56,StreamViewType: NEW_AND_OLD_IMAGES}
-             {ApproximateCreationDateTime: Tue Mar 20 09:50:00 PDT 2018,Keys: {Id={N: 1,}},OldImage: {Message={S: This item has changed,}, Id={N: 1,}},SequenceNumber: 300000000003218256413,SizeBytes: 36,StreamViewType: NEW_AND_OLD_IMAGES}
+            StreamRecord(ApproximateCreationDateTime=2025-04-09T13:11:58Z, Keys={Id=AttributeValue(S=4)}, NewImage={Message=AttributeValue(S=New Item!), Id=AttributeValue(S=4)}, SequenceNumber=2000001584047545833909, SizeBytes=22, StreamViewType=NEW_AND_OLD_IMAGES)
+            StreamRecord(ApproximateCreationDateTime=2025-04-09T13:11:58Z, Keys={Id=AttributeValue(S=4)}, NewImage={Message=AttributeValue(S=This is an updated item), Id=AttributeValue(S=4)}, OldImage={Message=AttributeValue(S=New Item!), Id=AttributeValue(S=4)}, SequenceNumber=2100003604869767892701, SizeBytes=55, StreamViewType=NEW_AND_OLD_IMAGES)
+            StreamRecord(ApproximateCreationDateTime=2025-04-09T13:11:58Z, Keys={Id=AttributeValue(S=4)}, OldImage={Message=AttributeValue(S=This is an updated item), Id=AttributeValue(S=4)}, SequenceNumber=2200001099771112898434, SizeBytes=36, StreamViewType=NEW_AND_OLD_IMAGES)
@@ -50,0 +53 @@ When you run the program, you will see output similar to the following.
+    Table StreamsDemoTable deleted.
@@ -56,4 +58,0 @@ When you run the program, you will see output similar to the following.
-    package com.amazon.codesamples;
-    
-    import java.util.ArrayList;
-    import java.util.Arrays;
@@ -64,28 +63,35 @@ When you run the program, you will see output similar to the following.
-    import com.amazonaws.AmazonClientException;
-    import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
-    import com.amazonaws.regions.Regions;
-    import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
-    import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
-    import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams;
-    import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreamsClientBuilder;
-    import com.amazonaws.services.dynamodbv2.model.AttributeAction;
-    import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
-    import com.amazonaws.services.dynamodbv2.model.AttributeValue;
-    import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate;
-    import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
-    import com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest;
-    import com.amazonaws.services.dynamodbv2.model.DescribeStreamResult;
-    import com.amazonaws.services.dynamodbv2.model.DescribeTableResult;
-    import com.amazonaws.services.dynamodbv2.model.GetRecordsRequest;
-    import com.amazonaws.services.dynamodbv2.model.GetRecordsResult;
-    import com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest;
-    import com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult;
-    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.Record;
-    import com.amazonaws.services.dynamodbv2.model.Shard;
-    import com.amazonaws.services.dynamodbv2.model.ShardIteratorType;
-    import com.amazonaws.services.dynamodbv2.model.StreamSpecification;
-    import com.amazonaws.services.dynamodbv2.model.StreamViewType;
-    import com.amazonaws.services.dynamodbv2.util.TableUtils;
+    import software.amazon.awssdk.core.waiters.WaiterResponse;
+    import software.amazon.awssdk.regions.Region;
+    import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+    import software.amazon.awssdk.services.dynamodb.model.AttributeAction;
+    import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
+    import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+    import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate;
+    import software.amazon.awssdk.services.dynamodb.model.BillingMode;
+    import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
+    import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse;
+    import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
+    import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest;
+    import software.amazon.awssdk.services.dynamodb.model.DescribeStreamRequest;
+    import software.amazon.awssdk.services.dynamodb.model.DescribeStreamResponse;
+    import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
+    import software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse;
+    import software.amazon.awssdk.services.dynamodb.model.DynamoDbException;
+    import software.amazon.awssdk.services.dynamodb.model.GetRecordsRequest;
+    import software.amazon.awssdk.services.dynamodb.model.GetRecordsResponse;
+    import software.amazon.awssdk.services.dynamodb.model.GetShardIteratorRequest;
+    import software.amazon.awssdk.services.dynamodb.model.GetShardIteratorResponse;
+    import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
+    import software.amazon.awssdk.services.dynamodb.model.KeyType;
+    import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
+    import software.amazon.awssdk.services.dynamodb.model.Record;
+    import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
+    import software.amazon.awssdk.services.dynamodb.model.Shard;
+    import software.amazon.awssdk.services.dynamodb.model.ShardFilter;
+    import software.amazon.awssdk.services.dynamodb.model.ShardFilterType;
+    import software.amazon.awssdk.services.dynamodb.model.ShardIteratorType;
+    import software.amazon.awssdk.services.dynamodb.model.StreamSpecification;
+    import software.amazon.awssdk.services.dynamodb.model.TableDescription;
+    import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
+    import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
+    import software.amazon.awssdk.services.dynamodb.waiters.DynamoDbWaiter;
@@ -95 +100,0 @@ When you run the program, you will see output similar to the following.
-            public static void main(String args[]) throws InterruptedException {
@@ -97,4 +102,11 @@ When you run the program, you will see output similar to the following.
-                    AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder
-                                    .standard()
-                                    .withRegion(Regions.US_EAST_2)
-                                    .withCredentials(new DefaultAWSCredentialsProviderChain())
+        public static void main(String[] args) {
+            final String usage = "Testing Streams Demo";
+            try {
+                System.out.println(usage);
+    
+                String tableName = "StreamsDemoTable";
+                String key = "Id";
+                System.out.println("Creating an Amazon DynamoDB table " + tableName + " with a simple primary key: " + key);
+                Region region = Region.US_WEST_2;
+                DynamoDbClient ddb = DynamoDbClient.builder()
+                        .region(region)
@@ -103,4 +115,2 @@ When you run the program, you will see output similar to the following.
-                    AmazonDynamoDBStreams streamsClient = AmazonDynamoDBStreamsClientBuilder
-                                    .standard()
-                                    .withRegion(Regions.US_EAST_2)
-                                    .withCredentials(new DefaultAWSCredentialsProviderChain())
+                DynamoDbStreamsClient ddbStreams = DynamoDbStreamsClient.builder()
+                        .region(region)
@@ -108,29 +118,4 @@ When you run the program, you will see output similar to the following.
-    
-                    // Create a table, with a stream enabled
-                    String tableName = "TestTableForStreams";
-    
-                    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>(
-                                    Arrays.asList(new AttributeDefinition()
-                                                    .withAttributeName("Id")
-                                                    .withAttributeType("N")));
-    
-                    ArrayList<KeySchemaElement> keySchema = new ArrayList<>(
-                                    Arrays.asList(new KeySchemaElement()
-                                                    .withAttributeName("Id")
-                                                    .withKeyType(KeyType.HASH))); // Partition key
-    
-                    StreamSpecification streamSpecification = new StreamSpecification()
-                                    .withStreamEnabled(true)
-                                    .withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES);
-    
-                    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
-                                    .withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions)
-                                    .withProvisionedThroughput(new ProvisionedThroughput()
-                                                    .withReadCapacityUnits(10L)
-                                                    .withWriteCapacityUnits(10L))
-                                    .withStreamSpecification(streamSpecification);
-    
-                    System.out.println("Issuing CreateTable request for " + tableName);
-                    dynamoDBClient.createTable(createTableRequest);
-                    System.out.println("Waiting for " + tableName + " to be created...");
-    
+                DescribeTableRequest describeTableRequest = DescribeTableRequest.builder()
+                        .tableName(tableName)
+                        .build();
+                TableDescription tableDescription = null;
@@ -138,3 +123,4 @@ When you run the program, you will see output similar to the following.
-                            TableUtils.waitUntilActive(dynamoDBClient, tableName);
-                    } catch (AmazonClientException e) {
-                            e.printStackTrace();
+                    tableDescription = ddb.describeTable(describeTableRequest).table();
+                }catch (Exception e){
+                    System.out.println("Table " + tableName + " does not exist.");
+                    tableDescription = createTable(ddb, tableName, key);
@@ -144,8 +130 @@ When you run the program, you will see output similar to the following.
-                    DescribeTableResult describeTableResult = dynamoDBClient.describeTable(tableName);
-                    String streamArn = describeTableResult.getTable().getLatestStreamArn();
-                    System.out.println("Current stream ARN for " + tableName + ": " +
-                                    describeTableResult.getTable().getLatestStreamArn());
-                    StreamSpecification streamSpec = describeTableResult.getTable().getStreamSpecification();
-                    System.out.println("Stream enabled: " + streamSpec.getStreamEnabled());
-                    System.out.println("Update view type: " + streamSpec.getStreamViewType());
-                    System.out.println();
+                String streamArn = tableDescription.latestStreamArn();
@@ -152,0 +132,6 @@ When you run the program, you will see output similar to the following.
+                StreamSpecification streamSpec = tableDescription.streamSpecification();
+                System.out.println("Current stream ARN for " + tableDescription.tableName() + ": " +
+                       streamArn);
+                System.out.println("Stream enabled: " + streamSpec.streamEnabled());
+                System.out.println("Update view type: " + streamSpec.streamViewType());
+                System.out.println();
@@ -161,5 +144 @@ When you run the program, you will see output similar to the following.
-                            Map<String, AttributeValue> item = new HashMap<>();
-                            item.put("Id", new AttributeValue().withN(i.toString()));
-                            item.put("Message", new AttributeValue().withS("New item!"));
-                            dynamoDBClient.putItem(tableName, item);
-    
+                    putItemInTable(key, i, tableName, ddb);
@@ -167,9 +146 @@ When you run the program, you will see output similar to the following.
-                            Map<String, AttributeValue> key = new HashMap<>();
-                            key.put("Id", new AttributeValue().withN(i.toString()));
-                            Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<>();
-                            attributeUpdates.put("Message", new AttributeValueUpdate()
-                                            .withAction(AttributeAction.PUT)
-                                            .withValue(new AttributeValue()
-                                                            .withS("This item has changed")));
-                            dynamoDBClient.updateItem(tableName, key, attributeUpdates);
-    
+                    updateItemInTable(key, i, tableName, ddb);
@@ -177 +148,18 @@ When you run the program, you will see output similar to the following.
-                            dynamoDBClient.deleteItem(tableName, key);
+                    deleteDynamoDBItem(key, i, tableName, ddb);