Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public static void ClientSupplierPutItemGetItem(
String ddbTableName,
String keyArn,
List<String> accountIds,
List<String> regions
List<String> regions,
String partitionKeyValue,
String sortKeyValue
) {
// 1. Create a single MRK multi-keyring.
// This can be either a single-region KMS key or an MRK.
Expand Down Expand Up @@ -166,9 +168,9 @@ public static void ClientSupplierPutItemGetItem(
final HashMap<String, AttributeValue> item = new HashMap<>();
item.put(
"partition_key",
AttributeValue.builder().s("clientSupplierItem").build()
AttributeValue.builder().s(partitionKeyValue).build()
);
item.put("sort_key", AttributeValue.builder().n("0").build());
item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build());
item.put(
"sensitive_data",
AttributeValue.builder().s("encrypt and sign me!").build()
Expand All @@ -191,9 +193,9 @@ public static void ClientSupplierPutItemGetItem(
final HashMap<String, AttributeValue> keyToGet = new HashMap<>();
keyToGet.put(
"partition_key",
AttributeValue.builder().s("clientSupplierItem").build()
AttributeValue.builder().s(partitionKeyValue).build()
);
keyToGet.put("sort_key", AttributeValue.builder().n("0").build());
keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build());

final GetItemRequest getRequest = GetItemRequest
.builder()
Expand Down Expand Up @@ -289,11 +291,11 @@ public static void ClientSupplierPutItemGetItem(
new HashMap<>();
onlyReplicaKeyKeyToGet.put(
"partition_key",
AttributeValue.builder().s("awsKmsMrkMultiKeyringItem").build()
AttributeValue.builder().s(partitionKeyValue).build()
);
onlyReplicaKeyKeyToGet.put(
"sort_key",
AttributeValue.builder().n("0").build()
AttributeValue.builder().n(sortKeyValue).build()
);

final GetItemRequest onlyReplicaKeyGetRequest = GetItemRequest
Expand Down Expand Up @@ -347,6 +349,6 @@ public static void main(final String[] args) {
) {
regions.add(args[i]);
}
ClientSupplierPutItemGetItem(ddbTableName, keyArn, accounts, regions);
ClientSupplierPutItemGetItem(ddbTableName, keyArn, accounts, regions, "clientSupplierItem", "0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate
*/
public class EnhancedPutGetExample {

public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) {
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
Expand Down Expand Up @@ -153,8 +153,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// The item will be encrypted client-side according to your
// configuration above before it is sent to DynamoDb.
final SimpleClass4 item = new SimpleClass4();
item.setPartitionKey("EnhancedPutGetExample");
item.setSortKey(0);
item.setPartitionKey(partitionKeyValue);
item.setSortKey(sortKeyValue);
item.setAttribute1("encrypt and sign me!");
item.setAttribute2("sign me!");
item.setAttribute3("ignore me!");
Expand All @@ -167,8 +167,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// original item.
final Key key = Key
.builder()
.partitionValue("EnhancedPutGetExample")
.sortValue(0)
.partitionValue(partitionKeyValue)
.sortValue(sortKeyValue)
.build();

final SimpleClass4 result =
Expand All @@ -181,7 +181,7 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {

// retrieve the same record via a Query
PageIterable<SimpleClass4> items = table.query(
QueryConditional.keyEqualTo(k -> k.partitionValue("EnhancedPutGetExample")
QueryConditional.keyEqualTo(k -> k.partitionValue(partitionKeyValue)
)
);
List<SimpleClass4> itemList = new ArrayList<SimpleClass4>();
Expand All @@ -199,6 +199,6 @@ public static void main(final String[] args) {
}
final String kmsKeyId = args[0];
final String ddbTableName = args[1];
PutItemGetItem(kmsKeyId, ddbTableName);
PutItemGetItem(kmsKeyId, ddbTableName, "EnhancedPutGetExample", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate
*/
public class LombokPutGetExample {

public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) {
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
Expand Down Expand Up @@ -163,8 +163,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// configuration above before it is sent to DynamoDb.
final SimpleViaLombok.SimpleViaLombokBuilder itemBuilder =
SimpleViaLombok.builder();
itemBuilder.partitionKey("LombokPutGetExample");
itemBuilder.sortKey(0);
itemBuilder.partitionKey(partitionKeyValue);
itemBuilder.sortKey(sortKeyValue);
itemBuilder.attribute1("encrypt and sign me!");
itemBuilder.attribute2("sign me!");
itemBuilder.attribute3("ignore me!");
Expand All @@ -176,8 +176,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// original item.
final Key key = Key
.builder()
.partitionValue("LombokPutGetExample")
.sortValue(0)
.partitionValue(partitionKeyValue)
.sortValue(sortKeyValue)
.build();

final SimpleViaLombok decrypted =
Expand Down Expand Up @@ -252,6 +252,6 @@ public static void main(final String[] args) {
}
final String kmsKeyId = args[0];
final String ddbTableName = args[1];
PutItemGetItem(kmsKeyId, ddbTableName);
PutItemGetItem(kmsKeyId, ddbTableName, "LombokPutGetExample", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate
*/
public class SingleTableExample {

public static void TransactWriteItems(String kmsKeyId, String ddbTableName) {
public static void TransactWriteItems(String kmsKeyId, String ddbTableName, String partitionKeyPrefix, int sortKeyValue) {
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
Expand Down Expand Up @@ -168,22 +168,22 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) {
// The item will be encrypted client-side according to your
// configuration above before it is sent to DynamoDb.
final SimpleClass item1 = new SimpleClass();
item1.setPartitionKey("EnhancedPutGetExample1");
item1.setSortKey(0);
item1.setPartitionKey(partitionKeyPrefix + "1");
item1.setSortKey(sortKeyValue);
item1.setAttribute1("item1 encrypt and sign me!");
item1.setAttribute2("item1 sign me!");
item1.setAttribute3("item1 ignore me!");

final SimpleClass2 item2 = new SimpleClass2();
item2.setPartitionKey("EnhancedPutGetExample2");
item2.setSortKey(0);
item2.setPartitionKey(partitionKeyPrefix + "2");
item2.setSortKey(sortKeyValue);
item2.setAttribute4("item2 encrypt and sign me!");
item2.setAttribute5("item2 sign me!");
item2.setAttribute3("item2 ignore me!");

final SimpleClass3 item3 = new SimpleClass3();
item3.setPartitionKey("EnhancedPutGetExample3");
item3.setSortKey(0);
item3.setPartitionKey(partitionKeyPrefix + "3");
item3.setSortKey(sortKeyValue);
item3.setAttribute6("item3 encrypt and sign me!");
item3.setAttribute2("item3 sign me!");
item3.setAttribute7("item3 sign and include me!");
Expand All @@ -202,16 +202,16 @@ public static void TransactWriteItems(String kmsKeyId, String ddbTableName) {
// The item will be decrypted client-side, and you will get back the
// original item.
final SimpleClass key1 = new SimpleClass();
key1.setPartitionKey("EnhancedPutGetExample1");
key1.setSortKey(0);
key1.setPartitionKey(partitionKeyPrefix + "1");
key1.setSortKey(sortKeyValue);

final SimpleClass2 key2 = new SimpleClass2();
key2.setPartitionKey("EnhancedPutGetExample2");
key2.setSortKey(0);
key2.setPartitionKey(partitionKeyPrefix + "2");
key2.setSortKey(sortKeyValue);

final SimpleClass3 key3 = new SimpleClass3();
key3.setPartitionKey("EnhancedPutGetExample3");
key3.setSortKey(0);
key3.setPartitionKey(partitionKeyPrefix + "3");
key3.setSortKey(sortKeyValue);

final TransactGetItemsEnhancedRequest getRequest =
TransactGetItemsEnhancedRequest
Expand Down Expand Up @@ -240,6 +240,6 @@ public static void main(final String[] args) {
}
final String kmsKeyId = args[0];
final String ddbTableName = args[1];
TransactWriteItems(kmsKeyId, ddbTableName);
TransactWriteItems(kmsKeyId, ddbTableName, "EnhancedPutGetExample", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ and uses the high level putItem() and getItem() APIs to demonstrate
*/
public class TableSchemaBuilderPutGetExample {

public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, int sortKeyValue) {
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
Expand Down Expand Up @@ -212,8 +212,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// The item will be encrypted client-side according to your
// configuration above before it is sent to DynamoDb.
final SimpleClass item = new SimpleClass();
item.setPartitionKey("TableSchemaBuilderPutGetExample");
item.setSortKey(0);
item.setPartitionKey(partitionKeyValue);
item.setSortKey(sortKeyValue);
item.setAttribute1("encrypt and sign me!");
item.setAttribute2("sign me!");
item.setAttribute3("ignore me!");
Expand All @@ -224,8 +224,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
// original item.
final Key key = Key
.builder()
.partitionValue("TableSchemaBuilderPutGetExample")
.sortValue(0)
.partitionValue(partitionKeyValue)
.sortValue(sortKeyValue)
.build();

final SimpleClass decrypted =
Expand Down Expand Up @@ -303,6 +303,6 @@ public static void main(final String[] args) {
}
final String kmsKeyId = args[0];
final String ddbTableName = args[1];
PutItemGetItem(kmsKeyId, ddbTableName);
PutItemGetItem(kmsKeyId, ddbTableName, "TableSchemaBuilderPutGetExample", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class ItemEncryptDecryptExample {

public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String partitionKeyValue, String sortKeyValue) {
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
Expand Down Expand Up @@ -124,9 +124,9 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
final Map<String, AttributeValue> originalItem = new HashMap<>();
originalItem.put(
"partition_key",
AttributeValue.builder().s("ItemEncryptDecryptExample").build()
AttributeValue.builder().s(partitionKeyValue).build()
);
originalItem.put("sort_key", AttributeValue.builder().n("0").build());
originalItem.put("sort_key", AttributeValue.builder().n(sortKeyValue).build());
originalItem.put(
"attribute1",
AttributeValue.builder().s("encrypt and sign me!").build()
Expand All @@ -150,8 +150,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
assert encryptedItem
.get("partition_key")
.s()
.equals("ItemEncryptDecryptExample");
assert encryptedItem.get("sort_key").n().equals("0");
.equals(partitionKeyValue);
assert encryptedItem.get("sort_key").n().equals(sortKeyValue);
assert encryptedItem.get("attribute1").b() != null;

// 7. Directly decrypt the encrypted item using the DynamoDb Item Encryptor
Expand All @@ -165,8 +165,8 @@ public static void PutItemGetItem(String kmsKeyId, String ddbTableName) {
assert decryptedItem
.get("partition_key")
.s()
.equals("ItemEncryptDecryptExample");
assert decryptedItem.get("sort_key").n().equals("0");
.equals(partitionKeyValue);
assert decryptedItem.get("sort_key").n().equals(sortKeyValue);
assert decryptedItem.get("attribute1").s().equals("encrypt and sign me!");
}

Expand All @@ -178,6 +178,6 @@ public static void main(final String[] args) {
}
final String kmsKeyId = args[0];
final String ddbTableName = args[1];
PutItemGetItem(kmsKeyId, ddbTableName);
PutItemGetItem(kmsKeyId, ddbTableName, "ItemEncryptDecryptExample", "0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public static void HierarchicalKeyringGetItemPutItem(
String tenant2BranchKeyId,
String keyStoreTableName,
String logicalKeyStoreName,
String kmsKeyId
String kmsKeyId,
String partitionKeyValue,
String sortKeyValue
) {
// Initial KeyStore Setup: This example requires that you have already
// created your KeyStore, and have populated it with two new branch keys.
Expand Down Expand Up @@ -235,8 +237,8 @@ public static void HierarchicalKeyringGetItemPutItem(
// based on the code we wrote in the ExampleBranchKeySupplier,
// `tenant1BranchKeyId` will be used to encrypt this item.
final HashMap<String, AttributeValue> item = new HashMap<>();
item.put("partition_key", AttributeValue.builder().s("tenant1Id").build());
item.put("sort_key", AttributeValue.builder().n("0").build());
item.put("partition_key", AttributeValue.builder().s(partitionKeyValue).build());
item.put("sort_key", AttributeValue.builder().n(sortKeyValue).build());
item.put(
"tenant_sensitive_data",
AttributeValue.builder().s("encrypt and sign me!").build()
Expand All @@ -262,9 +264,9 @@ public static void HierarchicalKeyringGetItemPutItem(
final HashMap<String, AttributeValue> keyToGet = new HashMap<>();
keyToGet.put(
"partition_key",
AttributeValue.builder().s("tenant1Id").build()
AttributeValue.builder().s(partitionKeyValue).build()
);
keyToGet.put("sort_key", AttributeValue.builder().n("0").build());
keyToGet.put("sort_key", AttributeValue.builder().n(sortKeyValue).build());

final GetItemRequest getRequest = GetItemRequest
.builder()
Expand Down Expand Up @@ -302,7 +304,9 @@ public static void main(final String[] args) {
tenant2BranchKeyId,
keyStoreTableName,
logicalKeyStoreName,
kmsKeyId
kmsKeyId,
"tenant1Id",
"0"
);
}
}
Loading
Loading