Skip to content

Commit d0bb1f3

Browse files
author
Lucas McDonald
committed
m
1 parent 64acb4a commit d0bb1f3

File tree

4 files changed

+22
-72
lines changed

4 files changed

+22
-72
lines changed

Examples/runtimes/python/DynamoDBEncryption/src/encrypted_paginator.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination
1515
For more information on paginating the Query operation, see:
1616
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.Pagination.html
17-
18-
This example also requires access to the KMS key ARN with permissions: (TODO)
1917
"""
2018

2119
import boto3
@@ -113,7 +111,6 @@ def encrypted_paginator_search_example(
113111
encrypted_client = EncryptedClient(
114112
client=boto3.client("dynamodb"),
115113
encryption_config=tables_config,
116-
expect_standard_dictionaries=True,
117114
)
118115

119116
# 6. Put 10 items into our table using the above client.
@@ -122,11 +119,11 @@ def encrypted_paginator_search_example(
122119
# client-side, according to our configuration.
123120
for i in range(10):
124121
item_to_encrypt = {
125-
"partition_key": "PythonEncryptedPaginatorSearchExample",
126-
"sort_key": i,
127-
"attribute1": "encrypt and sign me!",
128-
"attribute2": "sign me!",
129-
":attribute3": "ignore me!",
122+
"partition_key": {"S": "PythonEncryptedPaginatorSearchExample"},
123+
"sort_key": {"N": str(i)},
124+
"attribute1": {"S": "encrypt and sign me!"},
125+
"attribute2": {"S": "sign me!"},
126+
":attribute3": {"S": "ignore me!"},
130127
}
131128

132129
put_item_request = {
@@ -136,13 +133,10 @@ def encrypted_paginator_search_example(
136133

137134
put_item_response = encrypted_client.put_item(**put_item_request)
138135

139-
# print(f"{put_item_response=}")
140-
141136
# Demonstrate that PutItem succeeded
142137
assert put_item_response["ResponseMetadata"]["HTTPStatusCode"] == 200
143138

144-
### here
145-
139+
# 7. Search for the items using the EncryptedPaginator's Scan operation.
146140
encrypted_scan_paginator = encrypted_client.get_paginator("scan")
147141

148142
scan_item_request = {
@@ -157,28 +151,32 @@ def encrypted_paginator_search_example(
157151
# `MaxItems` configures the number of items the paginator will return before stopping the scan.
158152
# Scans are expensive, and we know that we only added 10 items, so this example will stop at 10.
159153
# The default is None; i.e. no size limit.
154+
# We set this for demonstration purposes only, but leaving this unset is recommended for most cases.
160155
"MaxItems": 10,
161156
# `PageSize` configures the maximum number of items that will be returned in a single page.
162157
# The default is to return ~1 MB of data.
158+
# We set this for demonstration purposes only, but leaving this unset is recommended for most cases.
163159
"PageSize": 5,
164160
},
165161
}
166162

167163
scan_response_iterator = encrypted_scan_paginator.paginate(**scan_item_request)
168164

165+
# 8. Iterate over the paginator's response pages.
166+
# Each page will contain a list of items.
167+
# Each item will have been decrypted by the EncryptedPaginator before being returned here.
169168
scan_collected_items = []
170-
171169
for scan_response_page in scan_response_iterator:
172-
# print(f'{scan_response_page=}')
173170
for item in scan_response_page["Items"]:
174-
if int(item["sort_key"]["N"]) % 2 == 0:
175-
scan_collected_items.append(item)
171+
scan_collected_items.append(item)
176172

177-
assert len(scan_collected_items) == 5
173+
# 9. Assert that we have received all 10 items correctly.
174+
# We do this for demonstration purposes only; you do not need to do this in your code.
175+
assert len(scan_collected_items) == 10
178176
for scan_collected_item in scan_collected_items:
179-
assert int(scan_collected_item["sort_key"]["N"]) % 2 == 0
180177
assert scan_collected_item["attribute1"] == {"S": "encrypt and sign me!"}
181178

179+
# 10. Search for the items using the EncryptedPaginator's Query operation.
182180
encrypted_query_paginator = encrypted_client.get_paginator("query")
183181

184182
query_item_request = {
@@ -194,18 +192,15 @@ def encrypted_paginator_search_example(
194192

195193
query_response_iterator = encrypted_query_paginator.paginate(**query_item_request)
196194

195+
# 11. Iterate over the paginator's response pages.
196+
# Each page will contain a list of items.
197+
# Each item will have been decrypted by the EncryptedPaginator before being returned here.
197198
query_collected_items = []
198-
199199
for query_response_page in query_response_iterator:
200200
for item in query_response_page["Items"]:
201201
query_collected_items.append(item)
202202

203-
assert len(query_collected_items) == 1
203+
# 12. Assert that we have received all 10 items correctly.
204+
# We do this for demonstration purposes only; you do not need to do this in your code.
205+
assert len(query_collected_items) == 10
204206
assert query_collected_items[0]["attribute1"] == {"S": "encrypt and sign me!"}
205-
206-
# # Demonstrate that GetItem succeeded
207-
# assert get_item_response["ResponseMetadata"]["HTTPStatusCode"] == 200
208-
# print(f"{item_to_encrypt=}")
209-
# print(f"{get_item_response['Item']=}")
210-
# # assert get_item_response["Item"] == item_to_encrypt
211-
# assert get_item_response["Item"]["attribute1"] == {"S" : "encrypt and sign me!"}

Examples/runtimes/python/DynamoDBEncryption/test/encrypted_client.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

Examples/runtimes/python/DynamoDBEncryption/test/encrypted_paginator.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

Examples/runtimes/python/DynamoDBEncryption/test/table.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)