@@ -5,30 +5,49 @@ import (
55 "fmt"
66
77 "github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/utils"
8- "github.com/aws/aws-sdk-go-v2/aws"
98 "github.com/aws/aws-sdk-go-v2/config"
109 "github.com/aws/aws-sdk-go-v2/service/dynamodb"
1110 "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
1211)
1312
14- // MigrationStep0 demonstrates plaintext database operations before encryption migration
13+ /*
14+ Migration Step 0: This is the pre-migration step for the
15+ plaintext-to-encrypted database migration, and is the starting
16+ state for our migration from a plaintext database to a
17+ client-side encrypted database encrypted using the
18+ AWS Database Encryption SDK for DynamoDb.
19+
20+ In this example, we configure a DynamoDbClient to
21+ write a plaintext record to a table and read that record.
22+ This emulates the starting state of a plaintext-to-encrypted
23+ database migration; i.e. a plaintext database you can
24+ read and write to with the DynamoDbClient.
25+
26+ Running this example requires access to the DDB Table whose name
27+ is provided in the function parameter.
28+ This table must be configured with the following
29+ primary key configuration:
30+ - Partition key is named "partition_key" with type (S)
31+ - Sort key is named "sort_key" with type (S)
32+ */
1533func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) {
16- // 1. Create a standard DynamoDB client (no encryption)
34+ // 1. Create a standard DynamoDB client
1735 cfg , err := config .LoadDefaultConfig (context .TODO ())
1836 utils .HandleError (err )
1937 ddb := dynamodb .NewFromConfig (cfg )
2038
21- // 2. Put an example item into our DynamoDB table in plaintext
39+ // 2. Put an example item into DynamoDB table
40+ // This item will be stored in plaintext.
2241 item := map [string ]types.AttributeValue {
2342 "partition_key" : & types.AttributeValueMemberS {Value : partitionKeyValue },
24- "sort_key" : & types.AttributeValueMemberN {Value : sortKeyValue },
43+ "sort_key" : & types.AttributeValueMemberN {Value : "0" },
2544 "attribute1" : & types.AttributeValueMemberS {Value : "this will be encrypted and signed" },
2645 "attribute2" : & types.AttributeValueMemberS {Value : "this will never be encrypted, but it will be signed" },
2746 "attribute3" : & types.AttributeValueMemberS {Value : "this will never be encrypted nor signed" },
2847 }
2948
3049 putInput := & dynamodb.PutItemInput {
31- TableName : aws . String ( ddbTableName ) ,
50+ TableName : & ddbTableName ,
3251 Item : item ,
3352 }
3453 _ , err = ddb .PutItem (context .TODO (), putInput )
@@ -41,7 +60,7 @@ func MigrationStep0(ddbTableName, partitionKeyValue, sortKeyValue string) {
4160 }
4261
4362 getInput := & dynamodb.GetItemInput {
44- TableName : aws . String ( ddbTableName ) ,
63+ TableName : & ddbTableName ,
4564 Key : key ,
4665 }
4766 result , err := ddb .GetItem (context .TODO (), getInput )
0 commit comments