Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c20581f

Browse files
author
Lucas McDonald
committedMay 1, 2025·
m
1 parent b227e64 commit c20581f

File tree

3 files changed

+57
-37
lines changed

3 files changed

+57
-37
lines changed
 

‎DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
# Initialize generated Dafny, then initialize externs
45
# Disable sorting imports; this order initializes code in the required order
56
# (generated Dafny, then externs)
6-
# ruff: noqa: I
7-
# Initialize generated Dafny
8-
# Initialize externs
9-
# noqa: F401, F403
10-
from .internaldafny import extern
7+
# ruff: noqa: I001
118
from .internaldafny.generated import module_
9+
from .internaldafny import extern
1210

1311
"""
1412
boto3 uses Python's decimal library to deserialize numbers retrieved by resources

‎DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/resource.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
self._encryption_config = encryption_config
4646

4747
def all(self) -> Generator[EncryptedTable, None, None]:
48-
"""Creates an iterable of all EncryptedTable resources in the collection.
48+
"""Create an iterable of all EncryptedTable resources in the collection.
4949
5050
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/tables.html#DynamoDB.ServiceResource.all
5151
@@ -56,7 +56,7 @@ def all(self) -> Generator[EncryptedTable, None, None]:
5656
yield from self._transform_table(self._collection.all)
5757

5858
def filter(self, **kwargs) -> Generator[EncryptedTable, None, None]:
59-
"""Creates an iterable of all EncryptedTable resources in the collection filtered by kwargs passed to method.
59+
"""Create an iterable of all EncryptedTable resources in the collection filtered by kwargs passed to method.
6060
6161
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/tables.html#filter
6262
@@ -67,7 +67,7 @@ def filter(self, **kwargs) -> Generator[EncryptedTable, None, None]:
6767
yield from self._transform_table(self._collection.filter, **kwargs)
6868

6969
def limit(self, **kwargs) -> Generator[EncryptedTable, None, None]:
70-
"""Creates an iterable of all EncryptedTable resources in the collection filtered by kwargs passed to method.
70+
"""Create an iterable of all EncryptedTable resources in the collection filtered by kwargs passed to method.
7171
7272
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/tables.html#limit
7373
@@ -78,8 +78,9 @@ def limit(self, **kwargs) -> Generator[EncryptedTable, None, None]:
7878
yield from self._transform_table(self._collection.limit, **kwargs)
7979

8080
def page_size(self, **kwargs) -> Generator[EncryptedTable, None, None]:
81-
"""Creates an iterable of all EncryptedTable resources in the collection,
82-
but limits the number of items returned by each service call by the specified amount.
81+
"""Create an iterable of all EncryptedTable resources in the collection.
82+
83+
This limits the number of items returned by each service call by the specified amount.
8384
8485
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/tables.html#page_size
8586
@@ -109,12 +110,38 @@ def _boto_client_attr_name(self) -> str:
109110

110111

111112
class EncryptedResource(EncryptedBotoInterface):
113+
"""Wrapper for a boto3 DynamoDB resource.
114+
115+
This class implements the complete boto3 DynamoDB resource API, allowing it to serve as a
116+
drop-in replacement that transparently handles encryption and decryption of items.
117+
118+
The API matches the standard boto3 DynamoDB resource interface:
119+
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/index.html
120+
121+
This class will encrypt/decrypt items for the following operations:
122+
* batch_get_item
123+
* batch_write_item
124+
125+
Calling Table() will return an EncryptedTable object.
126+
127+
Any other operations on this class will defer to the underlying boto3 DynamoDB resource's implementation
128+
and will not be encrypted/decrypted.
129+
130+
"""
131+
112132
def __init__(
113133
self,
114134
*,
115135
resource: ServiceResource,
116136
encryption_config: DynamoDbTablesEncryptionConfig,
117137
):
138+
"""Create an EncryptedResource object.
139+
140+
Args:
141+
resource (ServiceResource): Initialized boto3 DynamoDB resource
142+
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
143+
144+
"""
118145
self._resource = resource
119146
self._encryption_config = encryption_config
120147
self._transformer = DynamoDbEncryptionTransforms(config=encryption_config)
@@ -125,12 +152,12 @@ def __init__(
125152
)
126153

127154
def Table(self, name):
128-
"""Creates an EncryptedTable resource.
155+
"""Create an EncryptedTable resource.
129156
130157
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/Table.html
131158
132159
Args:
133-
name (str): The EncryptedTable's name. This must be set.
160+
name (str): The EncryptedTable's name identifier. This must be set.
134161
135162
Returns:
136163
EncryptedTable: An EncryptedTable resource
@@ -139,20 +166,16 @@ def Table(self, name):
139166
return EncryptedTable(table=self._resource.Table(name), encryption_config=self._encryption_config)
140167

141168
def batch_get_item(self, **kwargs):
142-
"""Gets multiple items from one or more tables. Decrypts any returned items.
169+
"""Get multiple items from one or more tables. Decrypts any returned items.
143170
144171
The parameters and return value match the boto3 DynamoDB batch_get_item API:
145172
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/batch_get_item.html
146173
147174
Args:
148-
RequestItems (dict): A map of table names to lists of keys to retrieve
149-
150-
These are only a list of required args; see boto3 docs for complete request structure.
175+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 batch_get_item API parameters.
151176
152177
Returns:
153-
dict: The response from DynamoDB containing the requested items.
154-
155-
See boto3 docs for complete response structure.
178+
dict: The response from DynamoDB. This matches the boto3 batch_get_item API response.
156179
157180
"""
158181
return self._resource_operation_logic(
@@ -170,20 +193,17 @@ def batch_get_item(self, **kwargs):
170193

171194
def batch_write_item(self, **kwargs):
172195
"""Put or delete multiple items in one or more tables.
196+
173197
For put operations, encrypts items before writing.
174198
175199
The parameters and return value match the boto3 DynamoDB batch_write_item API:
176200
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/service-resource/batch_write_item.html
177201
178202
Args:
179-
RequestItems (dict): A map of table names to lists of write operations
180-
181-
These are only a list of required args; see boto3 docs for complete request structure.
203+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 batch_write_item API parameters.
182204
183205
Returns:
184-
dict: The response from DynamoDB.
185-
186-
See boto3 docs for complete response structure.
206+
dict: The response from DynamoDB. This matches the boto3 batch_write_item API response.
187207
188208
"""
189209
return self._resource_operation_logic(

‎DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/table.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class EncryptedTable(EncryptedBotoInterface):
4444
* query
4545
* scan
4646
47-
Any other operations on this class will defer to the underlying boto3 DynamoDB Table's implementation.
47+
Calling batch_writer() will return a BatchWriter that transparently encrypts batch write requests.
4848
49-
Note: The update_item operation is not currently supported. Calling this operation will raise NotImplementedError.
49+
Any other operations on this class will defer to the underlying boto3 DynamoDB Table's implementation
50+
and will not be encrypted/decrypted.
5051
51-
EncryptedTable can also return a BatchWriter for transparent encryption of batch write requests.
52+
Note: The update_item operation is not currently supported. Calling this operation will raise NotImplementedError.
5253
"""
5354

5455
def __init__(
@@ -61,7 +62,8 @@ def __init__(
6162
6263
Args:
6364
table (ServiceResource): Initialized boto3 DynamoDB table
64-
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
65+
encryption_config (DynamoDbTablesEncryptionConfig): Initialized
66+
~aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.models.DynamoDbTablesEncryptionConfig~
6567
6668
"""
6769
self._table = table
@@ -79,10 +81,10 @@ def put_item(self, **kwargs) -> dict[str, Any]:
7981
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/put_item.html
8082
8183
Args:
82-
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
84+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 put_item API parameters.
8385
8486
Returns:
85-
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
87+
dict: The response from DynamoDB. This matches the boto3 put_item API response.
8688
8789
"""
8890
return self._table_operation_logic(
@@ -105,10 +107,10 @@ def get_item(self, **kwargs) -> dict[str, Any]:
105107
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/get_item.html
106108
107109
Args:
108-
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
110+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 get_item API parameters.
109111
110112
Returns:
111-
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
113+
dict: The response from DynamoDB. This matches the boto3 get_item API response.
112114
113115
"""
114116
return self._table_operation_logic(
@@ -131,10 +133,10 @@ def query(self, **kwargs) -> dict[str, Any]:
131133
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/query.html
132134
133135
Args:
134-
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
136+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 query API parameters.
135137
136138
Returns:
137-
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
139+
dict: The response from DynamoDB. This matches the boto3 query API response.
138140
139141
"""
140142
return self._table_operation_logic(
@@ -157,10 +159,10 @@ def scan(self, **kwargs) -> dict[str, Any]:
157159
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/scan.html
158160
159161
Args:
160-
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
162+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 scan API parameters.
161163
162164
Returns:
163-
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
165+
dict: The response from DynamoDB. This matches the boto3 scan API response.
164166
165167
"""
166168
return self._table_operation_logic(

0 commit comments

Comments
 (0)
Please sign in to comment.