Skip to content

Commit 849f5da

Browse files
use UUID
1 parent c166eab commit 849f5da

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/BasicPutGetExample.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import java.util.UUID;
56
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
67
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
78
import software.amazon.awssdk.services.dynamodb.model.*;
@@ -30,7 +31,7 @@
3031
*/
3132
public class BasicPutGetExample {
3233

33-
public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
34+
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String PartitionKeyName) {
3435
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
3536
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
3637
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
@@ -142,7 +143,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
142143
final HashMap<String, AttributeValue> item = new HashMap<>();
143144
item.put(
144145
"partition_key",
145-
AttributeValue.builder().s("BasicPutGetExample").build()
146+
AttributeValue.builder().s(PartitionKeyName).build()
146147
);
147148
item.put("sort_key", AttributeValue.builder().n("0").build());
148149
item.put(
@@ -169,7 +170,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
169170
final HashMap<String, AttributeValue> keyToGet = new HashMap<>();
170171
keyToGet.put(
171172
"partition_key",
172-
AttributeValue.builder().s("BasicPutGetExample").build()
173+
AttributeValue.builder().s(PartitionKeyName).build()
173174
);
174175
keyToGet.put("sort_key", AttributeValue.builder().n("0").build());
175176

@@ -201,6 +202,6 @@ public static void main(final String[] args) {
201202
}
202203
final String kmsKeyId = args[0];
203204
final String ddbTableName = args[1];
204-
PutItemGetItem(kmsKeyId, ddbTableName);
205+
PutItemGetItem(kmsKeyId, ddbTableName, "BasicPutGetExample");
205206
}
206207
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package software.amazon.cryptography.examples;
22

3+
import java.util.UUID;
34
import org.testng.annotations.Test;
45

56
public class TestBasicPutGetExample {
@@ -8,7 +9,8 @@ public class TestBasicPutGetExample {
89
public void TestPutGet() {
910
BasicPutGetExample.PutItemGetItem(
1011
TestUtils.TEST_KMS_KEY_ID,
11-
TestUtils.TEST_DDB_TABLE_NAME
12+
TestUtils.TEST_DDB_TABLE_NAME,
13+
"BasicPutGetExample" + UUID.randomUUID()
1214
);
1315
}
1416
}

0 commit comments

Comments
 (0)