From 2f2849d34b29953e9133641df6d87f87fb04b036 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 24 Mar 2026 15:48:00 -0700 Subject: [PATCH 01/32] Updated example in java to use partitions --- .../BasicSearchableEncryptionExample.java | 96 ++++++++++++------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 8434693712..ddcb1f0b0f 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -83,10 +83,11 @@ public static void PutItemQueryItemWithBeacon( // values are uniformly distributed across its range of possible values. // In many use cases, the prefix of an identifier encodes some information // about that identifier (e.g. zipcode and SSN prefixes encode geographic - // information), while the suffix does not and is more uniformly distributed. + // information), while the suffix does not encode such structure and tends + // to be closer to uniformly distributed, though not perfectly uniform. // We will assume that the inspector ID field matches a similar use case. - // So for this example, we only store and use the last - // 4 digits of the inspector ID, which we assume is uniformly distributed. + // For this example, we use only the last four digits of the inspector ID and apply two partitions, + // assuming the suffix has sufficient uniformity for this purpose. // Since the full ID's range is divisible by the range of the last 4 digits, // then the last 4 digits of the inspector ID are uniformly distributed // over the range from 0 to 9,999. @@ -126,13 +127,14 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) + .numberOfPartitions(2) .build(); standardBeaconList.add(last4Beacon); // The configured DDB table has a GSI on the `aws_dbe_b_unit` AttributeName. // This field holds a unit serial number. // For this example, this is a 12-digit integer from 0 to 999,999,999,999 (10^12 possible values). - // We will assume values for this attribute are uniformly distributed across this range. + // We will assume values for this attribute are uniformly distributed across this range using 2 partitions. // A single unit serial number may be assigned to multiple `work_id`s. // // This link provides guidance for choosing a beacon length: @@ -159,6 +161,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) + .numberOfPartitions(2) .build(); standardBeaconList.add(unitBeacon); @@ -191,6 +194,8 @@ public static void PutItemQueryItemWithBeacon( // 3. Create BeaconVersion. // The BeaconVersion inside the list holds the list of beacons on the table. // The BeaconVersion also stores information about the keystore. + // The BeaconVersion parameter specifies the maximumNumberOfPartitions associated with a given beacon configuration. + // "maximumNumberOfPartitions" must be greater than "numberOfPartitions"; we set it to 8 to allow room for future expansion. // BeaconVersion must be provided: // - keyStore: The keystore configured in step 2. // - keySource: A configuration for the key source. @@ -206,6 +211,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .standardBeacons(standardBeaconList) .version(1) // MUST be 1 + .maximumNumberOfPartitions(8) .keyStore(keyStore) .keySource( BeaconKeySource @@ -351,49 +357,69 @@ public static void PutItemQueryItemWithBeacon( // This procedure is internal to the client and is abstracted away from the user; // e.g. the user will only see "123456789012" and never // "098765432109", though the actual query returned both. + + List> allResults = new ArrayList<>(); + + Map expressionAttributesNames = new HashMap<>(); expressionAttributesNames.put("#last4", "inspector_id_last4"); expressionAttributesNames.put("#unit", "unit"); - Map expressionAttributeValues = new HashMap<>(); - expressionAttributeValues.put( - ":last4", - AttributeValue.builder().s("4321").build() - ); - expressionAttributeValues.put( - ":unit", - AttributeValue.builder().s("123456789012").build() - ); - - QueryRequest queryRequest = QueryRequest - .builder() - .tableName(ddbTableName) - .indexName(GSI_NAME) - .keyConditionExpression("#last4 = :last4 and #unit = :unit") - .expressionAttributeNames(expressionAttributesNames) - .expressionAttributeValues(expressionAttributeValues) - .build(); + // In this simple example, we know there are two buckets, + // but in general the number can be obtained using transformClient.getNumberOfQueries(query) + int numQueries = 2; + //We need to query for all possible parttions + + for (int partition = 0; partition < numQueries; partition++) { + Map expressionAttributeValues = new HashMap<>(); + expressionAttributeValues.put( + ":last4", + AttributeValue.builder().s("4321").build() + ); + expressionAttributeValues.put( + ":unit", + AttributeValue.builder().s("123456789012").build() + ); + expressionAttributeValues().put( + ":aws_dbe_partition", + AttributeValue.builder().n(Integer.toString(i)).build() + ); + + QueryRequest queryRequest = QueryRequest + .builder() + .tableName(ddbTableName) + .indexName(GSI_NAME) + .keyConditionExpression("#last4 = :last4 and #unit = :unit") + .expressionAttributeNames(expressionAttributesNames) + .expressionAttributeValues(expressionAttributeValues) + .build(); // GSIs do not update instantly // so if the results come back empty // we retry after a short sleep - for (int i = 0; i < 10; ++i) { - final QueryResponse queryResponse = ddb.query(queryRequest); - List> attributeValues = queryResponse.items(); - // Validate query was returned successfully - assert 200 == queryResponse.sdkHttpResponse().statusCode(); + for (int i = 0; i < 10; ++i) { + final QueryResponse queryResponse = ddb.query(queryRequest); + List> attributeValues = queryResponse.items(); + // Validate query was returned successfully + assert 200 == queryResponse.sdkHttpResponse().statusCode(); - // if no results, sleep and try again - if (attributeValues.size() == 0) { - try { - Thread.sleep(20); - } catch (Exception e) {} - continue; + // if no results, sleep and try again + if (attributeValues.size() == 0) { + try { + Thread.sleep(20); + } catch (Exception e) {} + continue; + } + else { + // Adding the result for partition i + allResults.addAll(queryResponse.items()); + } } + } // Validate only 1 item was returned: the item we just put - assert attributeValues.size() == 1; - final Map returnedItem = attributeValues.get(0); + assert allResults.size() == 1; + final Map returnedItem = allResults.get(0); // Validate the item has the expected attributes assert returnedItem.get("inspector_id_last4").s().equals("4321"); assert returnedItem.get("unit").s().equals("123456789012"); From 717f6094be5187dfae1dcbe771bf17cce492b4ca Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 25 Mar 2026 09:53:13 -0700 Subject: [PATCH 02/32] Fix partition variable usage in query request --- .../BasicSearchableEncryptionExample.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index ddcb1f0b0f..84e5782286 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -380,9 +380,8 @@ public static void PutItemQueryItemWithBeacon( ":unit", AttributeValue.builder().s("123456789012").build() ); - expressionAttributeValues().put( - ":aws_dbe_partition", - AttributeValue.builder().n(Integer.toString(i)).build() + expressionAttributeValues.put(":aws_dbe_partition", + AttributeValue.builder().n(Integer.toString(partition)).build() ); QueryRequest queryRequest = QueryRequest @@ -411,7 +410,7 @@ public static void PutItemQueryItemWithBeacon( continue; } else { - // Adding the result for partition i + // Adding the result for this partition allResults.addAll(queryResponse.items()); } } @@ -424,8 +423,8 @@ public static void PutItemQueryItemWithBeacon( assert returnedItem.get("inspector_id_last4").s().equals("4321"); assert returnedItem.get("unit").s().equals("123456789012"); break; - } } + public static void main(final String[] args) { if (args.length <= 1) { From 3e766c951429fdc27b90398630365a6c7158201f Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 25 Mar 2026 11:14:02 -0700 Subject: [PATCH 03/32] Fix break statement in BasicSearchableEncryptionExample --- .../searchableencryption/BasicSearchableEncryptionExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 84e5782286..d657210a17 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -412,6 +412,7 @@ public static void PutItemQueryItemWithBeacon( else { // Adding the result for this partition allResults.addAll(queryResponse.items()); + break; } } } @@ -422,7 +423,7 @@ public static void PutItemQueryItemWithBeacon( // Validate the item has the expected attributes assert returnedItem.get("inspector_id_last4").s().equals("4321"); assert returnedItem.get("unit").s().equals("123456789012"); - break; + } From 95948ae3ae3aedb3354587fbc43a1651cfa81899 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 25 Mar 2026 13:53:17 -0700 Subject: [PATCH 04/32] Add partition condition to query request --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index d657210a17..610b061d75 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -388,7 +388,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .tableName(ddbTableName) .indexName(GSI_NAME) - .keyConditionExpression("#last4 = :last4 and #unit = :unit") + .keyConditionExpression("#last4 = :last4 and #unit = :unit" and #partition = :partition") .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); From 95a85a532dee5ff77cb353278c38ade6ce53efa1 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 25 Mar 2026 14:02:34 -0700 Subject: [PATCH 05/32] Update BasicSearchableEncryptionExample.java Minor error --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 610b061d75..8e12b9c441 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -388,7 +388,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .tableName(ddbTableName) .indexName(GSI_NAME) - .keyConditionExpression("#last4 = :last4 and #unit = :unit" and #partition = :partition") + .keyConditionExpression("#last4 = :last4 and #unit = :unit and #partition = :partition") .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); From 02cd1dbc6570c2c44bd88d362878db6585c52a46 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 25 Mar 2026 15:20:16 -0700 Subject: [PATCH 06/32] Update BasicSearchableEncryptionExample.java --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 8e12b9c441..d657210a17 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -388,7 +388,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .tableName(ddbTableName) .indexName(GSI_NAME) - .keyConditionExpression("#last4 = :last4 and #unit = :unit and #partition = :partition") + .keyConditionExpression("#last4 = :last4 and #unit = :unit") .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); From d9be133d4167d50277b5c94de6b830eccaa577b0 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Thu, 26 Mar 2026 10:51:00 -0700 Subject: [PATCH 07/32] Update BasicSearchableEncryptionExample.java Adding GetNumberOfQueries and defaultNumberOfPartitions. --- .../BasicSearchableEncryptionExample.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index d657210a17..7c0fcdfe98 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -212,6 +212,7 @@ public static void PutItemQueryItemWithBeacon( .standardBeacons(standardBeaconList) .version(1) // MUST be 1 .maximumNumberOfPartitions(8) + .defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. .keyStore(keyStore) .keySource( BeaconKeySource @@ -365,14 +366,8 @@ public static void PutItemQueryItemWithBeacon( expressionAttributesNames.put("#last4", "inspector_id_last4"); expressionAttributesNames.put("#unit", "unit"); - // In this simple example, we know there are two buckets, - // but in general the number can be obtained using transformClient.getNumberOfQueries(query) - int numQueries = 2; - //We need to query for all possible parttions - - for (int partition = 0; partition < numQueries; partition++) { - Map expressionAttributeValues = new HashMap<>(); - expressionAttributeValues.put( + Map expressionAttributeValues = new HashMap<>(); + expressionAttributeValues.put( ":last4", AttributeValue.builder().s("4321").build() ); @@ -380,11 +375,8 @@ public static void PutItemQueryItemWithBeacon( ":unit", AttributeValue.builder().s("123456789012").build() ); - expressionAttributeValues.put(":aws_dbe_partition", - AttributeValue.builder().n(Integer.toString(partition)).build() - ); - - QueryRequest queryRequest = QueryRequest + + QueryRequest queryRequest = QueryRequest .builder() .tableName(ddbTableName) .indexName(GSI_NAME) @@ -393,6 +385,17 @@ public static void PutItemQueryItemWithBeacon( .expressionAttributeValues(expressionAttributeValues) .build(); + + // The number can be obtained using transformClient.getNumberOfQueries(query) + int numQueries = transformClient.GetNumberOfQueries(queryRequest); + + //We need to query for all possible parttions + + for (int partition = 0; partition < numQueries; partition++) { + + queryRequest.ExpressionAttributeValues.Add(":aws_dbe_partition", N(i.to_string()) + + // GSIs do not update instantly // so if the results come back empty // we retry after a short sleep From 396c1a3ea2adc36559893a4a3729213279d11148 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Thu, 26 Mar 2026 10:52:36 -0700 Subject: [PATCH 08/32] Update BasicSearchableEncryptionExample.java Change i to partition --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 7c0fcdfe98..8fe59373b6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -393,7 +393,7 @@ public static void PutItemQueryItemWithBeacon( for (int partition = 0; partition < numQueries; partition++) { - queryRequest.ExpressionAttributeValues.Add(":aws_dbe_partition", N(i.to_string()) + queryRequest.ExpressionAttributeValues.Add(":aws_dbe_partition", N(partition.to_string()) // GSIs do not update instantly From 94191f134da5a974c39daa2842123c96b1e21afe Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Thu, 26 Mar 2026 16:03:46 -0700 Subject: [PATCH 09/32] Update BasicSearchableEncryptionExample.java Adding updatedQueryRequest --- .../BasicSearchableEncryptionExample.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 8fe59373b6..7b5782c55f 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -392,15 +392,26 @@ public static void PutItemQueryItemWithBeacon( //We need to query for all possible parttions for (int partition = 0; partition < numQueries; partition++) { - - queryRequest.ExpressionAttributeValues.Add(":aws_dbe_partition", N(partition.to_string()) - + expressionAttributeValues.put( + ":aws_dbe_partition", + AttributeValue.builder().n(partition.to_string()).build() + ); + + QueryRequest updatedQueryRequest = QueryRequest + .builder() + .tableName(ddbTableName) + .indexName(GSI_NAME) + .keyConditionExpression("#last4 = :last4 and #unit = :unit") + .expressionAttributeNames(expressionAttributesNames) + .expressionAttributeValues(expressionAttributeValues) + .build(); + // GSIs do not update instantly // so if the results come back empty // we retry after a short sleep for (int i = 0; i < 10; ++i) { - final QueryResponse queryResponse = ddb.query(queryRequest); + final QueryResponse queryResponse = ddb.query(updatedQueryRequest); List> attributeValues = queryResponse.items(); // Validate query was returned successfully assert 200 == queryResponse.sdkHttpResponse().statusCode(); From 1bc11f65759339f6710eb15825d2be9ab3176b94 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Fri, 27 Mar 2026 10:26:27 -0700 Subject: [PATCH 10/32] Update BasicSearchableEncryptionExample.java --- .../BasicSearchableEncryptionExample.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 7b5782c55f..cab746e9bb 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.DynamoDbEncryptionTransforms; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; @@ -384,18 +385,23 @@ public static void PutItemQueryItemWithBeacon( .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); + + DynamoDbEncryptionTransforms transformClient = + DynamoDbEncryptionTransforms.builder() + .config(config) + .build(); // The number can be obtained using transformClient.getNumberOfQueries(query) - int numQueries = transformClient.GetNumberOfQueries(queryRequest); + int numQueries = transformClient.getNumberOfQueries(queryRequest); - //We need to query for all possible parttions + //We need to query for all possible partitions for (int partition = 0; partition < numQueries; partition++) { expressionAttributeValues.put( ":aws_dbe_partition", - AttributeValue.builder().n(partition.to_string()).build() + AttributeValue.builder().n(Integer.toString(partition)).build() ); QueryRequest updatedQueryRequest = QueryRequest From 6b073f0923e4eacbaec8c6f055b7a2abf1810b80 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Fri, 27 Mar 2026 11:29:45 -0700 Subject: [PATCH 11/32] Update Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java Co-authored-by: Rishav karanjit --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index cab746e9bb..3082a4fe5a 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -388,7 +388,7 @@ public static void PutItemQueryItemWithBeacon( DynamoDbEncryptionTransforms transformClient = DynamoDbEncryptionTransforms.builder() - .config(config) + .DynamoDbTablesEncryptionConfig(config) .build(); From 26892a85e2f93f5094bf4a15d26cbb4a531173bb Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Fri, 27 Mar 2026 11:31:37 -0700 Subject: [PATCH 12/32] Update Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java Co-authored-by: Rishav karanjit --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 3082a4fe5a..a52e7ba309 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -393,7 +393,7 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) - int numQueries = transformClient.getNumberOfQueries(queryRequest); + int numQueries = transformClient.GetNumberOfQueries(queryRequest); //We need to query for all possible partitions From 5452fbe85ef2ef273fb3d6cb9d8b95e2adb81dbb Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Fri, 27 Mar 2026 14:41:52 -0700 Subject: [PATCH 13/32] Update BasicSearchableEncryptionExample.java From 57bc0566e519bfb2c4bf291849d6f1ac4406dd1b Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Mon, 30 Mar 2026 13:30:25 -0700 Subject: [PATCH 14/32] Update BasicSearchableEncryptionExample.java Adding correct usage of DynamoDbTablesEncryptionConfig --- .../BasicSearchableEncryptionExample.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index a52e7ba309..b2ec3da134 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -385,15 +385,20 @@ public static void PutItemQueryItemWithBeacon( .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); + + Map tableConfigs = new HashMap<>(); + tableConfigs.put(ddbTableName, config); + DynamoDbEncryptionTransforms transformClient = DynamoDbEncryptionTransforms.builder() - .DynamoDbTablesEncryptionConfig(config) + .DynamoDbTablesEncryptionConfig(tableConfigs) .build(); // The number can be obtained using transformClient.getNumberOfQueries(query) - int numQueries = transformClient.GetNumberOfQueries(queryRequest); + //int numQueries = transformClient.GetNumberOfQueries(queryRequest); + int numQueries = 1; //We need to query for all possible partitions From 76bdd6eff779449c87f97265dfd879ff5bee5c89 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Mon, 30 Mar 2026 13:50:18 -0700 Subject: [PATCH 15/32] Refactor DynamoDB encryption configuration Removed unnecessary table configuration setup for DynamoDB. --- .../searchableencryption/BasicSearchableEncryptionExample.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index b2ec3da134..b85a843876 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -386,9 +386,6 @@ public static void PutItemQueryItemWithBeacon( .expressionAttributeValues(expressionAttributeValues) .build(); - Map tableConfigs = new HashMap<>(); - tableConfigs.put(ddbTableName, config); - DynamoDbEncryptionTransforms transformClient = DynamoDbEncryptionTransforms.builder() From 87c30968988b616b9f3fd2ed3c3728394e4c1640 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Mon, 30 Mar 2026 14:39:01 -0700 Subject: [PATCH 16/32] Fix DynamoDbTablesEncryptionConfig initialization --- .../BasicSearchableEncryptionExample.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index b85a843876..5a53d7ba8d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -385,11 +385,15 @@ public static void PutItemQueryItemWithBeacon( .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) .build(); - + + DynamoDbTablesEncryptionConfig tablesConfig = + DynamoDbTablesEncryptionConfig.builder() + .tableEncryptionConfigs(tableConfigs) + .build(); DynamoDbEncryptionTransforms transformClient = DynamoDbEncryptionTransforms.builder() - .DynamoDbTablesEncryptionConfig(tableConfigs) + .DynamoDbTablesEncryptionConfig(tablesConfig) .build(); From d4c995015b2c84158656f154b8e86cd37033002e Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 09:57:17 -0700 Subject: [PATCH 17/32] Change numQueries from 1 to 2 --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 5a53d7ba8d..57f8c63042 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -399,7 +399,7 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) //int numQueries = transformClient.GetNumberOfQueries(queryRequest); - int numQueries = 1; + int numQueries = 2; //We need to query for all possible partitions From 1800890900cafb774eba93b201dd53b91a6aac41 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 10:53:33 -0700 Subject: [PATCH 18/32] Update BasicSearchableEncryptionExample.java Testing a value that is not power of 2 --- .../BasicSearchableEncryptionExample.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 57f8c63042..9f90fa6a74 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -128,7 +128,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - .numberOfPartitions(2) + .numberOfPartitions(3) .build(); standardBeaconList.add(last4Beacon); @@ -162,7 +162,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) - .numberOfPartitions(2) + .numberOfPartitions(3) .build(); standardBeaconList.add(unitBeacon); @@ -212,8 +212,8 @@ public static void PutItemQueryItemWithBeacon( .builder() .standardBeacons(standardBeaconList) .version(1) // MUST be 1 - .maximumNumberOfPartitions(8) - .defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. + .maximumNumberOfPartitions(3) + .defaultNumberOfPartitions(3) //For beacons that do not require partitioning, only a single partition is used. .keyStore(keyStore) .keySource( BeaconKeySource @@ -399,7 +399,7 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) //int numQueries = transformClient.GetNumberOfQueries(queryRequest); - int numQueries = 2; + int numQueries = 3; //We need to query for all possible partitions From 90c966bece9a1ddf299fe2c9c9807536686e1426 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 11:33:22 -0700 Subject: [PATCH 19/32] Modify partition settings in BasicSearchableEncryptionExample Updated maximumNumberOfPartitions to 4 and clarified defaultNumberOfPartitions constraints. --- .../BasicSearchableEncryptionExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 9f90fa6a74..f12505fa19 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -212,8 +212,8 @@ public static void PutItemQueryItemWithBeacon( .builder() .standardBeacons(standardBeaconList) .version(1) // MUST be 1 - .maximumNumberOfPartitions(3) - .defaultNumberOfPartitions(3) //For beacons that do not require partitioning, only a single partition is used. + .maximumNumberOfPartitions(4) + .defaultNumberOfPartitions(3) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. .keyStore(keyStore) .keySource( BeaconKeySource From 0e034b7ad44113d5da7f04ff17623ce86beb37b3 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 12:04:43 -0700 Subject: [PATCH 20/32] Refactor numQueries retrieval using queryInputTransform --- .../BasicSearchableEncryptionExample.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index f12505fa19..f33f1f5b2c 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -399,7 +399,16 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) //int numQueries = transformClient.GetNumberOfQueries(queryRequest); - int numQueries = 3; + QueryInputTransformInput transformInput = QueryInputTransformInput.builder() + .logicalTableName(ddbTableName) + .queryRequest(queryRequest) + .build(); + + QueryInputTransformOutput transformed = transformClient.queryInputTransform(transformInput); + + int numQueries = transformClient.getNumberOfQueries(transformed); + + //int numQueries = 1; //We need to query for all possible partitions From 4426629700e73cf3693de3ceb25ba967e1d76492 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 12:36:54 -0700 Subject: [PATCH 21/32] Modify beacon partitioning and query handling Updated number of partitions for beacons and adjusted related logic to ensure correct handling of query results. --- .../BasicSearchableEncryptionExample.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index f33f1f5b2c..940168b081 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -30,6 +30,8 @@ import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsHierarchicalKeyringInput; import software.amazon.cryptography.materialproviders.model.MaterialProvidersConfig; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformInput; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformOutput; /* This example demonstrates how to set up a beacon on an encrypted attribute, @@ -128,7 +130,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - .numberOfPartitions(3) + .numberOfPartitions(1) .build(); standardBeaconList.add(last4Beacon); @@ -162,7 +164,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) - .numberOfPartitions(3) + .numberOfPartitions(1) .build(); standardBeaconList.add(unitBeacon); @@ -213,7 +215,7 @@ public static void PutItemQueryItemWithBeacon( .standardBeacons(standardBeaconList) .version(1) // MUST be 1 .maximumNumberOfPartitions(4) - .defaultNumberOfPartitions(3) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. + .defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. .keyStore(keyStore) .keySource( BeaconKeySource @@ -406,7 +408,7 @@ public static void PutItemQueryItemWithBeacon( QueryInputTransformOutput transformed = transformClient.queryInputTransform(transformInput); - int numQueries = transformClient.getNumberOfQueries(transformed); + int numQueries = transformClient.GetNumberOfQueries(transformed); //int numQueries = 1; @@ -446,14 +448,16 @@ public static void PutItemQueryItemWithBeacon( } else { // Adding the result for this partition - allResults.addAll(queryResponse.items()); + allResults.addAll(attributeValues); break; } } } // Validate only 1 item was returned: the item we just put - assert allResults.size() == 1; + if (allResults.size() != 1) { + throw new RuntimeException("Expected exactly one result, got " + allResults.size()); + } final Map returnedItem = allResults.get(0); // Validate the item has the expected attributes assert returnedItem.get("inspector_id_last4").s().equals("4321"); From df2e135e0be7d268d84f832926a8f1749a861be3 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 14:15:00 -0700 Subject: [PATCH 22/32] Rename logicalTableName to tableName in transform input --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 940168b081..a202fd385d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -402,7 +402,7 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) //int numQueries = transformClient.GetNumberOfQueries(queryRequest); QueryInputTransformInput transformInput = QueryInputTransformInput.builder() - .logicalTableName(ddbTableName) + .tableName(ddbTableName) .queryRequest(queryRequest) .build(); From 6940b55990c16d0aa8c3145e06cc048535367bfe Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 14:35:29 -0700 Subject: [PATCH 23/32] Refactor query input transformation and number retrieval --- .../BasicSearchableEncryptionExample.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index a202fd385d..9557974b34 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -401,14 +401,15 @@ public static void PutItemQueryItemWithBeacon( // The number can be obtained using transformClient.getNumberOfQueries(query) //int numQueries = transformClient.GetNumberOfQueries(queryRequest); - QueryInputTransformInput transformInput = QueryInputTransformInput.builder() - .tableName(ddbTableName) - .queryRequest(queryRequest) - .build(); + GetNumberOfQueriesInput numberOfQueriesInput = GetNumberOfQueriesInput + .builder() + .input(queryRequest) + .build(); - QueryInputTransformOutput transformed = transformClient.queryInputTransform(transformInput); - - int numQueries = transformClient.GetNumberOfQueries(transformed); + GetNumberOfQueriesOutput numberOfQueriesOutput = + transformClient.GetNumberOfQueries(numberOfQueriesInput); + + int numQueries = numberOfQueriesOutput.numberOfQueries(); //int numQueries = 1; From 4e96f5863f2e2007100e97cb27ead6710f70ae7a Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 15:42:48 -0700 Subject: [PATCH 24/32] Update BasicSearchableEncryptionExample.java --- .../searchableencryption/BasicSearchableEncryptionExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 9557974b34..8a3c0e7c27 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -32,7 +32,7 @@ import software.amazon.cryptography.materialproviders.model.MaterialProvidersConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformInput; import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformOutput; - +import software.amazon.cryptography.keystore.model.CreateKeyOutput; /* This example demonstrates how to set up a beacon on an encrypted attribute, put an item with the beacon, and query against that beacon. From 3ed55894c27f62ff34d5ece48bab58f98535f65f Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 31 Mar 2026 16:07:17 -0700 Subject: [PATCH 25/32] Remove unused imports in BasicSearchableEncryptionExample Removed unused imports related to QueryInputTransform. --- .../BasicSearchableEncryptionExample.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 8a3c0e7c27..30dc515f53 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -30,9 +30,8 @@ import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsHierarchicalKeyringInput; import software.amazon.cryptography.materialproviders.model.MaterialProvidersConfig; -import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformInput; -import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.QueryInputTransformOutput; -import software.amazon.cryptography.keystore.model.CreateKeyOutput; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesInput; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesOutput; /* This example demonstrates how to set up a beacon on an encrypted attribute, put an item with the beacon, and query against that beacon. From 28decbf88fab2e2dfa585f0d8f3169627621d03f Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Fri, 3 Apr 2026 14:12:38 -0700 Subject: [PATCH 26/32] Update BasicSearchableEncryptionExample.java --- .../BasicSearchableEncryptionExample.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 30dc515f53..bfd0f21855 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -129,14 +129,14 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - .numberOfPartitions(1) + .numberOfPartitions(2) .build(); standardBeaconList.add(last4Beacon); // The configured DDB table has a GSI on the `aws_dbe_b_unit` AttributeName. // This field holds a unit serial number. // For this example, this is a 12-digit integer from 0 to 999,999,999,999 (10^12 possible values). - // We will assume values for this attribute are uniformly distributed across this range using 2 partitions. + // We will assume values for this attribute are uniformly distributed across this range using 1 partitions. // A single unit serial number may be assigned to multiple `work_id`s. // // This link provides guidance for choosing a beacon length: @@ -409,9 +409,7 @@ public static void PutItemQueryItemWithBeacon( transformClient.GetNumberOfQueries(numberOfQueriesInput); int numQueries = numberOfQueriesOutput.numberOfQueries(); - - //int numQueries = 1; - + //We need to query for all possible partitions for (int partition = 0; partition < numQueries; partition++) { From f63a6255626bc379ad7041cf3b9cf3c8297ba933 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 7 Apr 2026 14:05:07 -0700 Subject: [PATCH 27/32] Update BasicSearchableEncryptionExample.java --- .../BasicSearchableEncryptionExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index bfd0f21855..999a5b6f44 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -129,7 +129,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - .numberOfPartitions(2) + //.numberOfPartitions(2) .build(); standardBeaconList.add(last4Beacon); @@ -214,7 +214,7 @@ public static void PutItemQueryItemWithBeacon( .standardBeacons(standardBeaconList) .version(1) // MUST be 1 .maximumNumberOfPartitions(4) - .defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. + //.defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. .keyStore(keyStore) .keySource( BeaconKeySource From e3d2dc0aac7f0c5928d3f0e0e8940b4e3d96111f Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 8 Apr 2026 11:39:01 -0700 Subject: [PATCH 28/32] Update number of partitions in StandardBeacon configuration --- .../BasicSearchableEncryptionExample.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 999a5b6f44..f9211d99e6 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -129,7 +129,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - //.numberOfPartitions(2) + .numberOfPartitions(2) .build(); standardBeaconList.add(last4Beacon); @@ -163,7 +163,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) - .numberOfPartitions(1) + .numberOfPartitions(2) .build(); standardBeaconList.add(unitBeacon); @@ -213,7 +213,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .standardBeacons(standardBeaconList) .version(1) // MUST be 1 - .maximumNumberOfPartitions(4) + .maximumNumberOfPartitions(2) //.defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. .keyStore(keyStore) .keySource( @@ -409,7 +409,10 @@ public static void PutItemQueryItemWithBeacon( transformClient.GetNumberOfQueries(numberOfQueriesInput); int numQueries = numberOfQueriesOutput.numberOfQueries(); - + if ( numQueries != 2) { + throw new RuntimeException("Expected to query 2 partitions, but numQueries is " + numQueries); + } + //We need to query for all possible partitions for (int partition = 0; partition < numQueries; partition++) { From 866f70a35f1d0a77283dd22475d353981f9f92d6 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 8 Apr 2026 18:00:05 -0700 Subject: [PATCH 29/32] Comment out numberOfPartitions in StandardBeacons Comment out the numberOfPartitions setting for two StandardBeacons. --- .../BasicSearchableEncryptionExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index f9211d99e6..b50586476b 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -129,7 +129,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - .numberOfPartitions(2) + //.numberOfPartitions(2) .build(); standardBeaconList.add(last4Beacon); @@ -163,7 +163,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) - .numberOfPartitions(2) + //.numberOfPartitions(2) .build(); standardBeaconList.add(unitBeacon); From 8ebae717ce6ddf10c58606dd47a41c30cf2d2354 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Wed, 8 Apr 2026 19:21:43 -0700 Subject: [PATCH 30/32] Update BasicSearchableEncryptionExample.java --- .../BasicSearchableEncryptionExample.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index b50586476b..7ff63b545d 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -88,7 +88,7 @@ public static void PutItemQueryItemWithBeacon( // information), while the suffix does not encode such structure and tends // to be closer to uniformly distributed, though not perfectly uniform. // We will assume that the inspector ID field matches a similar use case. - // For this example, we use only the last four digits of the inspector ID and apply two partitions, + // For this example, we use only the last four digits of the inspector ID and apply one partitions, // assuming the suffix has sufficient uniformity for this purpose. // Since the full ID's range is divisible by the range of the last 4 digits, // then the last 4 digits of the inspector ID are uniformly distributed @@ -129,7 +129,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("inspector_id_last4") .length(10) - //.numberOfPartitions(2) + .numberOfPartitions(1) .build(); standardBeaconList.add(last4Beacon); @@ -163,7 +163,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .name("unit") .length(30) - //.numberOfPartitions(2) + .numberOfPartitions(1) .build(); standardBeaconList.add(unitBeacon); @@ -409,8 +409,8 @@ public static void PutItemQueryItemWithBeacon( transformClient.GetNumberOfQueries(numberOfQueriesInput); int numQueries = numberOfQueriesOutput.numberOfQueries(); - if ( numQueries != 2) { - throw new RuntimeException("Expected to query 2 partitions, but numQueries is " + numQueries); + if ( numQueries != 1) { + throw new RuntimeException("Expected to query 1 partitions, but numQueries is " + numQueries); } //We need to query for all possible partitions From ef6ae97ce60694645f8dde300a875a0d117d3f12 Mon Sep 17 00:00:00 2001 From: Mahnush Movahedi Date: Tue, 5 May 2026 16:00:48 -0700 Subject: [PATCH 31/32] Format Java file with prettier --- .../BasicSearchableEncryptionExample.java | 181 +++++++++--------- 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 7ff63b545d..6af488d3bf 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.DynamoDbEncryptionTransforms; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; @@ -21,6 +20,9 @@ import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.SearchConfig; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.SingleKeyStore; import software.amazon.cryptography.dbencryptionsdk.dynamodb.model.StandardBeacon; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.DynamoDbEncryptionTransforms; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesInput; +import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesOutput; import software.amazon.cryptography.dbencryptionsdk.structuredencryption.model.CryptoAction; import software.amazon.cryptography.keystore.KeyStore; import software.amazon.cryptography.keystore.model.CreateKeyOutput; @@ -30,8 +32,7 @@ import software.amazon.cryptography.materialproviders.MaterialProviders; import software.amazon.cryptography.materialproviders.model.CreateAwsKmsHierarchicalKeyringInput; import software.amazon.cryptography.materialproviders.model.MaterialProvidersConfig; -import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesInput; -import software.amazon.cryptography.dbencryptionsdk.dynamodb.transforms.model.GetNumberOfQueriesOutput; + /* This example demonstrates how to set up a beacon on an encrypted attribute, put an item with the beacon, and query against that beacon. @@ -85,10 +86,10 @@ public static void PutItemQueryItemWithBeacon( // values are uniformly distributed across its range of possible values. // In many use cases, the prefix of an identifier encodes some information // about that identifier (e.g. zipcode and SSN prefixes encode geographic - // information), while the suffix does not encode such structure and tends + // information), while the suffix does not encode such structure and tends // to be closer to uniformly distributed, though not perfectly uniform. // We will assume that the inspector ID field matches a similar use case. - // For this example, we use only the last four digits of the inspector ID and apply one partitions, + // For this example, we use only the last four digits of the inspector ID and apply one partitions, // assuming the suffix has sufficient uniformity for this purpose. // Since the full ID's range is divisible by the range of the last 4 digits, // then the last 4 digits of the inspector ID are uniformly distributed @@ -196,7 +197,7 @@ public static void PutItemQueryItemWithBeacon( // 3. Create BeaconVersion. // The BeaconVersion inside the list holds the list of beacons on the table. // The BeaconVersion also stores information about the keystore. - // The BeaconVersion parameter specifies the maximumNumberOfPartitions associated with a given beacon configuration. + // The BeaconVersion parameter specifies the maximumNumberOfPartitions associated with a given beacon configuration. // "maximumNumberOfPartitions" must be greater than "numberOfPartitions"; we set it to 8 to allow room for future expansion. // BeaconVersion must be provided: // - keyStore: The keystore configured in step 2. @@ -213,7 +214,7 @@ public static void PutItemQueryItemWithBeacon( .builder() .standardBeacons(standardBeaconList) .version(1) // MUST be 1 - .maximumNumberOfPartitions(2) + .maximumNumberOfPartitions(2) //.defaultNumberOfPartitions(1) //For beacons that do not require partitioning, only a single partition is used. must be 0 < defaultNumberOfPartitions < maximumNumberOfPartitions. .keyStore(keyStore) .keySource( @@ -244,13 +245,12 @@ public static void PutItemQueryItemWithBeacon( .builder() .MaterialProvidersConfig(MaterialProvidersConfig.builder().build()) .build(); - CreateAwsKmsHierarchicalKeyringInput keyringInput = - CreateAwsKmsHierarchicalKeyringInput - .builder() - .branchKeyId(branchKeyId) - .keyStore(keyStore) - .ttlSeconds(6000l) - .build(); + CreateAwsKmsHierarchicalKeyringInput keyringInput = CreateAwsKmsHierarchicalKeyringInput + .builder() + .branchKeyId(branchKeyId) + .keyStore(keyStore) + .ttlSeconds(6000l) + .build(); final IKeyring kmsKeyring = matProv.CreateAwsKmsHierarchicalKeyring( keyringInput ); @@ -264,17 +264,22 @@ public static void PutItemQueryItemWithBeacon( // Any attributes that will be used in beacons must be configured as ENCRYPT_AND_SIGN. final Map attributeActionsOnEncrypt = new HashMap<>(); attributeActionsOnEncrypt.put("work_id", CryptoAction.SIGN_ONLY); // Our partition attribute must be SIGN_ONLY - attributeActionsOnEncrypt.put("inspection_date", CryptoAction.SIGN_ONLY); // Our sort attribute must be SIGN_ONLY + attributeActionsOnEncrypt.put( + "inspection_date", + CryptoAction.SIGN_ONLY + ); // Our sort attribute must be SIGN_ONLY attributeActionsOnEncrypt.put( "inspector_id_last4", CryptoAction.ENCRYPT_AND_SIGN ); // Beaconized attributes must be encrypted - attributeActionsOnEncrypt.put("unit", CryptoAction.ENCRYPT_AND_SIGN); // Beaconized attributes must be encrypted + attributeActionsOnEncrypt.put( + "unit", + CryptoAction.ENCRYPT_AND_SIGN + ); // Beaconized attributes must be encrypted // 6. Create the DynamoDb Encryption configuration for the table we will be writing to. // The beaconVersions are added to the search configuration. - final Map tableConfigs = - new HashMap<>(); + final Map tableConfigs = new HashMap<>(); final DynamoDbTableEncryptionConfig config = DynamoDbTableEncryptionConfig .builder() .logicalTableName(ddbTableName) @@ -293,16 +298,15 @@ public static void PutItemQueryItemWithBeacon( tableConfigs.put(ddbTableName, config); // 7. Create the DynamoDb Encryption Interceptor - DynamoDbEncryptionInterceptor encryptionInterceptor = - DynamoDbEncryptionInterceptor - .builder() - .config( - DynamoDbTablesEncryptionConfig - .builder() - .tableEncryptionConfigs(tableConfigs) - .build() - ) - .build(); + DynamoDbEncryptionInterceptor encryptionInterceptor = DynamoDbEncryptionInterceptor + .builder() + .config( + DynamoDbTablesEncryptionConfig + .builder() + .tableEncryptionConfigs(tableConfigs) + .build() + ) + .build(); // 8. Create a new AWS SDK DynamoDb client using the DynamoDb Encryption Interceptor above final DynamoDbClient ddb = DynamoDbClient @@ -363,65 +367,65 @@ public static void PutItemQueryItemWithBeacon( List> allResults = new ArrayList<>(); - Map expressionAttributesNames = new HashMap<>(); expressionAttributesNames.put("#last4", "inspector_id_last4"); expressionAttributesNames.put("#unit", "unit"); Map expressionAttributeValues = new HashMap<>(); expressionAttributeValues.put( - ":last4", - AttributeValue.builder().s("4321").build() - ); - expressionAttributeValues.put( - ":unit", - AttributeValue.builder().s("123456789012").build() - ); + ":last4", + AttributeValue.builder().s("4321").build() + ); + expressionAttributeValues.put( + ":unit", + AttributeValue.builder().s("123456789012").build() + ); - QueryRequest queryRequest = QueryRequest - .builder() - .tableName(ddbTableName) - .indexName(GSI_NAME) - .keyConditionExpression("#last4 = :last4 and #unit = :unit") - .expressionAttributeNames(expressionAttributesNames) - .expressionAttributeValues(expressionAttributeValues) - .build(); - - DynamoDbTablesEncryptionConfig tablesConfig = - DynamoDbTablesEncryptionConfig.builder() - .tableEncryptionConfigs(tableConfigs) - .build(); - - DynamoDbEncryptionTransforms transformClient = - DynamoDbEncryptionTransforms.builder() - .DynamoDbTablesEncryptionConfig(tablesConfig) - .build(); + QueryRequest queryRequest = QueryRequest + .builder() + .tableName(ddbTableName) + .indexName(GSI_NAME) + .keyConditionExpression("#last4 = :last4 and #unit = :unit") + .expressionAttributeNames(expressionAttributesNames) + .expressionAttributeValues(expressionAttributeValues) + .build(); + + DynamoDbTablesEncryptionConfig tablesConfig = DynamoDbTablesEncryptionConfig + .builder() + .tableEncryptionConfigs(tableConfigs) + .build(); + + DynamoDbEncryptionTransforms transformClient = DynamoDbEncryptionTransforms + .builder() + .DynamoDbTablesEncryptionConfig(tablesConfig) + .build(); - // The number can be obtained using transformClient.getNumberOfQueries(query) - //int numQueries = transformClient.GetNumberOfQueries(queryRequest); + //int numQueries = transformClient.GetNumberOfQueries(queryRequest); GetNumberOfQueriesInput numberOfQueriesInput = GetNumberOfQueriesInput - .builder() - .input(queryRequest) - .build(); + .builder() + .input(queryRequest) + .build(); + + GetNumberOfQueriesOutput numberOfQueriesOutput = transformClient.GetNumberOfQueries( + numberOfQueriesInput + ); - GetNumberOfQueriesOutput numberOfQueriesOutput = - transformClient.GetNumberOfQueries(numberOfQueriesInput); - int numQueries = numberOfQueriesOutput.numberOfQueries(); - if ( numQueries != 1) { - throw new RuntimeException("Expected to query 1 partitions, but numQueries is " + numQueries); - } - - //We need to query for all possible partitions - - for (int partition = 0; partition < numQueries; partition++) { + if (numQueries != 1) { + throw new RuntimeException( + "Expected to query 1 partitions, but numQueries is " + numQueries + ); + } + //We need to query for all possible partitions + + for (int partition = 0; partition < numQueries; partition++) { expressionAttributeValues.put( ":aws_dbe_partition", AttributeValue.builder().n(Integer.toString(partition)).build() ); - + QueryRequest updatedQueryRequest = QueryRequest .builder() .tableName(ddbTableName) @@ -429,11 +433,11 @@ public static void PutItemQueryItemWithBeacon( .keyConditionExpression("#last4 = :last4 and #unit = :unit") .expressionAttributeNames(expressionAttributesNames) .expressionAttributeValues(expressionAttributeValues) - .build(); - - // GSIs do not update instantly - // so if the results come back empty - // we retry after a short sleep + .build(); + + // GSIs do not update instantly + // so if the results come back empty + // we retry after a short sleep for (int i = 0; i < 10; ++i) { final QueryResponse queryResponse = ddb.query(updatedQueryRequest); List> attributeValues = queryResponse.items(); @@ -446,26 +450,23 @@ public static void PutItemQueryItemWithBeacon( Thread.sleep(20); } catch (Exception e) {} continue; - } - else { - // Adding the result for this partition - allResults.addAll(attributeValues); - break; + } else { + // Adding the result for this partition + allResults.addAll(attributeValues); + break; } } } - // Validate only 1 item was returned: the item we just put - if (allResults.size() != 1) { - throw new RuntimeException("Expected exactly one result, got " + allResults.size()); - } - final Map returnedItem = allResults.get(0); - // Validate the item has the expected attributes - assert returnedItem.get("inspector_id_last4").s().equals("4321"); - assert returnedItem.get("unit").s().equals("123456789012"); - + // Validate only 1 item was returned: the item we just put + if (allResults.size() != 1) { + throw new RuntimeException("Expected exactly one result, got " + allResults.size()); + } + final Map returnedItem = allResults.get(0); + // Validate the item has the expected attributes + assert returnedItem.get("inspector_id_last4").s().equals("4321"); + assert returnedItem.get("unit").s().equals("123456789012"); } - public static void main(final String[] args) { if (args.length <= 1) { From c6222ad5533a9c7535cd57aea2dda9cfd68e24ea Mon Sep 17 00:00:00 2001 From: mahnush Date: Thu, 7 May 2026 23:31:14 +0000 Subject: [PATCH 32/32] correct formatting --- .../BasicSearchableEncryptionExample.java | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java index 6af488d3bf..2aff3e4cb8 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/BasicSearchableEncryptionExample.java @@ -245,12 +245,13 @@ public static void PutItemQueryItemWithBeacon( .builder() .MaterialProvidersConfig(MaterialProvidersConfig.builder().build()) .build(); - CreateAwsKmsHierarchicalKeyringInput keyringInput = CreateAwsKmsHierarchicalKeyringInput - .builder() - .branchKeyId(branchKeyId) - .keyStore(keyStore) - .ttlSeconds(6000l) - .build(); + CreateAwsKmsHierarchicalKeyringInput keyringInput = + CreateAwsKmsHierarchicalKeyringInput + .builder() + .branchKeyId(branchKeyId) + .keyStore(keyStore) + .ttlSeconds(6000l) + .build(); final IKeyring kmsKeyring = matProv.CreateAwsKmsHierarchicalKeyring( keyringInput ); @@ -264,22 +265,17 @@ public static void PutItemQueryItemWithBeacon( // Any attributes that will be used in beacons must be configured as ENCRYPT_AND_SIGN. final Map attributeActionsOnEncrypt = new HashMap<>(); attributeActionsOnEncrypt.put("work_id", CryptoAction.SIGN_ONLY); // Our partition attribute must be SIGN_ONLY - attributeActionsOnEncrypt.put( - "inspection_date", - CryptoAction.SIGN_ONLY - ); // Our sort attribute must be SIGN_ONLY + attributeActionsOnEncrypt.put("inspection_date", CryptoAction.SIGN_ONLY); // Our sort attribute must be SIGN_ONLY attributeActionsOnEncrypt.put( "inspector_id_last4", CryptoAction.ENCRYPT_AND_SIGN ); // Beaconized attributes must be encrypted - attributeActionsOnEncrypt.put( - "unit", - CryptoAction.ENCRYPT_AND_SIGN - ); // Beaconized attributes must be encrypted + attributeActionsOnEncrypt.put("unit", CryptoAction.ENCRYPT_AND_SIGN); // Beaconized attributes must be encrypted // 6. Create the DynamoDb Encryption configuration for the table we will be writing to. // The beaconVersions are added to the search configuration. - final Map tableConfigs = new HashMap<>(); + final Map tableConfigs = + new HashMap<>(); final DynamoDbTableEncryptionConfig config = DynamoDbTableEncryptionConfig .builder() .logicalTableName(ddbTableName) @@ -298,15 +294,16 @@ public static void PutItemQueryItemWithBeacon( tableConfigs.put(ddbTableName, config); // 7. Create the DynamoDb Encryption Interceptor - DynamoDbEncryptionInterceptor encryptionInterceptor = DynamoDbEncryptionInterceptor - .builder() - .config( - DynamoDbTablesEncryptionConfig - .builder() - .tableEncryptionConfigs(tableConfigs) - .build() - ) - .build(); + DynamoDbEncryptionInterceptor encryptionInterceptor = + DynamoDbEncryptionInterceptor + .builder() + .config( + DynamoDbTablesEncryptionConfig + .builder() + .tableEncryptionConfigs(tableConfigs) + .build() + ) + .build(); // 8. Create a new AWS SDK DynamoDb client using the DynamoDb Encryption Interceptor above final DynamoDbClient ddb = DynamoDbClient @@ -407,9 +404,8 @@ public static void PutItemQueryItemWithBeacon( .input(queryRequest) .build(); - GetNumberOfQueriesOutput numberOfQueriesOutput = transformClient.GetNumberOfQueries( - numberOfQueriesInput - ); + GetNumberOfQueriesOutput numberOfQueriesOutput = + transformClient.GetNumberOfQueries(numberOfQueriesInput); int numQueries = numberOfQueriesOutput.numberOfQueries(); if (numQueries != 1) { @@ -440,7 +436,8 @@ public static void PutItemQueryItemWithBeacon( // we retry after a short sleep for (int i = 0; i < 10; ++i) { final QueryResponse queryResponse = ddb.query(updatedQueryRequest); - List> attributeValues = queryResponse.items(); + List> attributeValues = + queryResponse.items(); // Validate query was returned successfully assert 200 == queryResponse.sdkHttpResponse().statusCode(); @@ -460,7 +457,9 @@ public static void PutItemQueryItemWithBeacon( // Validate only 1 item was returned: the item we just put if (allResults.size() != 1) { - throw new RuntimeException("Expected exactly one result, got " + allResults.size()); + throw new RuntimeException( + "Expected exactly one result, got " + allResults.size() + ); } final Map returnedItem = allResults.get(0); // Validate the item has the expected attributes