@@ -5,30 +5,49 @@ import (
5
5
"fmt"
6
6
7
7
"github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/utils"
8
- "github.com/aws/aws-sdk-go-v2/aws"
9
8
"github.com/aws/aws-sdk-go-v2/config"
10
9
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
11
10
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
12
11
)
13
12
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
+ */
15
33
func MigrationStep0 (ddbTableName , partitionKeyValue , sortKeyValue string ) {
16
- // 1. Create a standard DynamoDB client (no encryption)
34
+ // 1. Create a standard DynamoDB client
17
35
cfg , err := config .LoadDefaultConfig (context .TODO ())
18
36
utils .HandleError (err )
19
37
ddb := dynamodb .NewFromConfig (cfg )
20
38
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.
22
41
item := map [string ]types.AttributeValue {
23
42
"partition_key" : & types.AttributeValueMemberS {Value : partitionKeyValue },
24
- "sort_key" : & types.AttributeValueMemberN {Value : sortKeyValue },
43
+ "sort_key" : & types.AttributeValueMemberN {Value : "0" },
25
44
"attribute1" : & types.AttributeValueMemberS {Value : "this will be encrypted and signed" },
26
45
"attribute2" : & types.AttributeValueMemberS {Value : "this will never be encrypted, but it will be signed" },
27
46
"attribute3" : & types.AttributeValueMemberS {Value : "this will never be encrypted nor signed" },
28
47
}
29
48
30
49
putInput := & dynamodb.PutItemInput {
31
- TableName : aws . String ( ddbTableName ) ,
50
+ TableName : & ddbTableName ,
32
51
Item : item ,
33
52
}
34
53
_ , err = ddb .PutItem (context .TODO (), putInput )
@@ -41,7 +60,7 @@ func MigrationStep0(ddbTableName, partitionKeyValue, sortKeyValue string) {
41
60
}
42
61
43
62
getInput := & dynamodb.GetItemInput {
44
- TableName : aws . String ( ddbTableName ) ,
63
+ TableName : & ddbTableName ,
45
64
Key : key ,
46
65
}
47
66
result , err := ddb .GetItem (context .TODO (), getInput )
0 commit comments