@@ -21,18 +21,32 @@ import (
21
21
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
22
22
)
23
23
24
+ /*
25
+ This example sets up DynamoDb Encryption for the AWS SDK client
26
+ and uses the low level PutItem and GetItem DDB APIs to demonstrate
27
+ putting a client-side encrypted item into DynamoDb
28
+ and then retrieving and decrypting that item from DynamoDb.
29
+
30
+ Running this example requires access to the DDB Table whose name
31
+ is provided in CLI arguments.
32
+ This table must be configured with the following
33
+ primary key configuration:
34
+ - Partition key is named "partition_key" with type (S)
35
+ - Sort key is named "sort_key" with type (N)
36
+ */
24
37
func MultiPutGetExample (kmsKeyID , ddbTableName string ) {
25
38
cfg , err := config .LoadDefaultConfig (context .TODO ())
39
+ utils .HandleError (err )
26
40
// Initialize the mpl client
27
41
matProv , err := mpl .NewClient (mpltypes.MaterialProvidersConfig {})
28
42
utils .HandleError (err )
29
43
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
30
44
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
31
45
// We will use the `CreateAwsKmsMultiKeyring` method to create this keyring,
32
46
// as it will correctly handle both single region and Multi-Region KMS Keys.
33
- generatorKeyId := kmsKeyID
47
+ generatorKeyID := kmsKeyID
34
48
awsKmsMultiKeyringInput := mpltypes.CreateAwsKmsMultiKeyringInput {
35
- Generator : & generatorKeyId ,
49
+ Generator : & generatorKeyID ,
36
50
}
37
51
keyring , err := matProv .CreateAwsKmsMultiKeyring (context .Background (), awsKmsMultiKeyringInput )
38
52
utils .HandleError (err )
@@ -92,7 +106,15 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
92
106
AttributeActionsOnEncrypt : attributeActions ,
93
107
Keyring : keyring ,
94
108
AllowedUnsignedAttributePrefix : & allowedUnsignedAttributePrefix ,
95
- AlgorithmSuiteId : & algorithmSuiteID ,
109
+ // Specifying an algorithm suite is not required,
110
+ // but is done here to demonstrate how to do so.
111
+ // We suggest using the
112
+ // `ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384_SYMSIG_HMAC_SHA384` suite,
113
+ // which includes AES-GCM with key derivation, signing, and key commitment.
114
+ // This is also the default algorithm suite if one is not specified in this config.
115
+ // For more information on supported algorithm suites, see:
116
+ // https://docs.aws.amazon.com/database-encryption-sdk/latest/devguide/supported-algorithms.html
117
+ AlgorithmSuiteId : & algorithmSuiteID ,
96
118
}
97
119
tableConfigsMap := make (map [string ]dbesdkdynamodbencryptiontypes.DynamoDbTableEncryptionConfig )
98
120
tableConfigsMap [ddbTableName ] = tableConfig
@@ -108,7 +130,7 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
108
130
// Before the item gets sent to DynamoDb, it will be encrypted
109
131
// client-side, according to our configuration.
110
132
item := map [string ]types.AttributeValue {
111
- "partition_key" : & types.AttributeValueMemberS {Value : "BasicPutGetExample " },
133
+ "partition_key" : & types.AttributeValueMemberS {Value : "WriteItemExample " },
112
134
"sort_key" : & types.AttributeValueMemberN {Value : "0" },
113
135
"attribute1" : & types.AttributeValueMemberS {Value : "encrypt and sign me!" },
114
136
"attribute2" : & types.AttributeValueMemberS {Value : "sign me!" },
@@ -138,7 +160,7 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
138
160
// The client will decrypt the item client-side, and return
139
161
// back the original item.
140
162
key := map [string ]types.AttributeValue {
141
- "partition_key" : & types.AttributeValueMemberS {Value : "BasicPutGetExample " },
163
+ "partition_key" : & types.AttributeValueMemberS {Value : "WriteItemExample " },
142
164
"sort_key" : & types.AttributeValueMemberN {Value : "0" },
143
165
}
144
166
getInput := & dynamodb.GetItemInput {
0 commit comments