@@ -21,18 +21,32 @@ import (
2121 "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
2222)
2323
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+ */
2437func MultiPutGetExample (kmsKeyID , ddbTableName string ) {
2538 cfg , err := config .LoadDefaultConfig (context .TODO ())
39+ utils .HandleError (err )
2640 // Initialize the mpl client
2741 matProv , err := mpl .NewClient (mpltypes.MaterialProvidersConfig {})
2842 utils .HandleError (err )
2943 // 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
3044 // For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
3145 // We will use the `CreateAwsKmsMultiKeyring` method to create this keyring,
3246 // as it will correctly handle both single region and Multi-Region KMS Keys.
33- generatorKeyId := kmsKeyID
47+ generatorKeyID := kmsKeyID
3448 awsKmsMultiKeyringInput := mpltypes.CreateAwsKmsMultiKeyringInput {
35- Generator : & generatorKeyId ,
49+ Generator : & generatorKeyID ,
3650 }
3751 keyring , err := matProv .CreateAwsKmsMultiKeyring (context .Background (), awsKmsMultiKeyringInput )
3852 utils .HandleError (err )
@@ -92,7 +106,15 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
92106 AttributeActionsOnEncrypt : attributeActions ,
93107 Keyring : keyring ,
94108 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 ,
96118 }
97119 tableConfigsMap := make (map [string ]dbesdkdynamodbencryptiontypes.DynamoDbTableEncryptionConfig )
98120 tableConfigsMap [ddbTableName ] = tableConfig
@@ -108,7 +130,7 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
108130 // Before the item gets sent to DynamoDb, it will be encrypted
109131 // client-side, according to our configuration.
110132 item := map [string ]types.AttributeValue {
111- "partition_key" : & types.AttributeValueMemberS {Value : "BasicPutGetExample " },
133+ "partition_key" : & types.AttributeValueMemberS {Value : "WriteItemExample " },
112134 "sort_key" : & types.AttributeValueMemberN {Value : "0" },
113135 "attribute1" : & types.AttributeValueMemberS {Value : "encrypt and sign me!" },
114136 "attribute2" : & types.AttributeValueMemberS {Value : "sign me!" },
@@ -138,7 +160,7 @@ func MultiPutGetExample(kmsKeyID, ddbTableName string) {
138160 // The client will decrypt the item client-side, and return
139161 // back the original item.
140162 key := map [string ]types.AttributeValue {
141- "partition_key" : & types.AttributeValueMemberS {Value : "BasicPutGetExample " },
163+ "partition_key" : & types.AttributeValueMemberS {Value : "WriteItemExample " },
142164 "sort_key" : & types.AttributeValueMemberN {Value : "0" },
143165 }
144166 getInput := & dynamodb.GetItemInput {
0 commit comments