19
19
IdempotencyItemAlreadyExistsError ,
20
20
IdempotencyValidationError ,
21
21
)
22
+ from aws_lambda_powertools .utilities .validation .jmespath_functions import PowertoolsFunctions
22
23
23
24
logger = logging .getLogger (__name__ )
24
25
@@ -112,6 +113,7 @@ def __init__(
112
113
use_local_cache : bool = False ,
113
114
local_cache_max_items : int = 256 ,
114
115
hash_function : str = "md5" ,
116
+ jmespath_options : Dict = None ,
115
117
) -> None :
116
118
"""
117
119
Initialize the base persistence layer
@@ -130,6 +132,8 @@ def __init__(
130
132
Max number of items to store in local cache, by default 1024
131
133
hash_function: str, optional
132
134
Function to use for calculating hashes, by default md5.
135
+ jmespath_options : Dict
136
+ Alternative JMESPath options to be included when filtering expr
133
137
"""
134
138
self .event_key_jmespath = event_key_jmespath
135
139
if self .event_key_jmespath :
@@ -143,6 +147,9 @@ def __init__(
143
147
self .validation_key_jmespath = jmespath .compile (payload_validation_jmespath )
144
148
self .payload_validation_enabled = True
145
149
self .hash_function = getattr (hashlib , hash_function )
150
+ if not jmespath_options :
151
+ jmespath_options = {"custom_functions" : PowertoolsFunctions ()}
152
+ self .jmespath_options = jmespath_options
146
153
147
154
def _get_hashed_idempotency_key (self , lambda_event : Dict [str , Any ]) -> str :
148
155
"""
@@ -160,8 +167,12 @@ def _get_hashed_idempotency_key(self, lambda_event: Dict[str, Any]) -> str:
160
167
161
168
"""
162
169
data = lambda_event
170
+
163
171
if self .event_key_jmespath :
164
- data = self .event_key_compiled_jmespath .search (lambda_event )
172
+ data = self .event_key_compiled_jmespath .search (
173
+ lambda_event , options = jmespath .Options (** self .jmespath_options )
174
+ )
175
+
165
176
return self ._generate_hash (data )
166
177
167
178
def _get_hashed_payload (self , lambda_event : Dict [str , Any ]) -> str :
0 commit comments