14
14
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination
15
15
For more information on paginating the Query operation, see:
16
16
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)
19
17
"""
20
18
21
19
import boto3
@@ -113,7 +111,6 @@ def encrypted_paginator_search_example(
113
111
encrypted_client = EncryptedClient (
114
112
client = boto3 .client ("dynamodb" ),
115
113
encryption_config = tables_config ,
116
- expect_standard_dictionaries = True ,
117
114
)
118
115
119
116
# 6. Put 10 items into our table using the above client.
@@ -122,11 +119,11 @@ def encrypted_paginator_search_example(
122
119
# client-side, according to our configuration.
123
120
for i in range (10 ):
124
121
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!"} ,
130
127
}
131
128
132
129
put_item_request = {
@@ -136,13 +133,10 @@ def encrypted_paginator_search_example(
136
133
137
134
put_item_response = encrypted_client .put_item (** put_item_request )
138
135
139
- # print(f"{put_item_response=}")
140
-
141
136
# Demonstrate that PutItem succeeded
142
137
assert put_item_response ["ResponseMetadata" ]["HTTPStatusCode" ] == 200
143
138
144
- ### here
145
-
139
+ # 7. Search for the items using the EncryptedPaginator's Scan operation.
146
140
encrypted_scan_paginator = encrypted_client .get_paginator ("scan" )
147
141
148
142
scan_item_request = {
@@ -157,28 +151,32 @@ def encrypted_paginator_search_example(
157
151
# `MaxItems` configures the number of items the paginator will return before stopping the scan.
158
152
# Scans are expensive, and we know that we only added 10 items, so this example will stop at 10.
159
153
# 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.
160
155
"MaxItems" : 10 ,
161
156
# `PageSize` configures the maximum number of items that will be returned in a single page.
162
157
# 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.
163
159
"PageSize" : 5 ,
164
160
},
165
161
}
166
162
167
163
scan_response_iterator = encrypted_scan_paginator .paginate (** scan_item_request )
168
164
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.
169
168
scan_collected_items = []
170
-
171
169
for scan_response_page in scan_response_iterator :
172
- # print(f'{scan_response_page=}')
173
170
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 )
176
172
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
178
176
for scan_collected_item in scan_collected_items :
179
- assert int (scan_collected_item ["sort_key" ]["N" ]) % 2 == 0
180
177
assert scan_collected_item ["attribute1" ] == {"S" : "encrypt and sign me!" }
181
178
179
+ # 10. Search for the items using the EncryptedPaginator's Query operation.
182
180
encrypted_query_paginator = encrypted_client .get_paginator ("query" )
183
181
184
182
query_item_request = {
@@ -194,18 +192,15 @@ def encrypted_paginator_search_example(
194
192
195
193
query_response_iterator = encrypted_query_paginator .paginate (** query_item_request )
196
194
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.
197
198
query_collected_items = []
198
-
199
199
for query_response_page in query_response_iterator :
200
200
for item in query_response_page ["Items" ]:
201
201
query_collected_items .append (item )
202
202
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
204
206
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!"}
0 commit comments