You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -209,7 +209,7 @@ Imagine the function executes successfully, but the client never receives the re
209
209
!!! warning "Idempotency for JSON payloads"
210
210
The payload extracted by the `event_key_jmespath` is treated as a string by default, so will be sensitive to differences in whitespace even when the JSON payload itself is identical.
211
211
212
-
To alter this behaviour, we can use the [JMESPath built-in function](/utilities/jmespath_functions) *powertools_json()* to treat the payload as a JSON object rather than a string.
212
+
To alter this behaviour, we can use the [JMESPath built-in function](jmespath_functions.md#powertools_json-function) `powertools_json()` to treat the payload as a JSON object rather than a string.
Copy file name to clipboardExpand all lines: docs/utilities/jmespath_functions.md
+115-16
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,106 @@ title: JMESPath Functions
3
3
description: Utility
4
4
---
5
5
6
-
You might have events or responses that contain non-encoded JSON, where you need to decode so that you can access portions of the object or ensure the Powertools utility receives a JSON object. This is a common use case when using the [validation](/utilities/validation) or [idempotency](/utilities/idempotency) utilities.
6
+
!!! tip "JMESPath is a query language for JSON used by AWS CLI, AWS Python SDK, and AWS Lambda Powertools for Python."
7
7
8
-
## Built-in JMESPath functions
8
+
Built-in [JMESPath](https://jmespath.org/){target="_blank"} Functions to easily deserialize common encoded JSON payloads in Lambda functions.
9
+
10
+
## Key features
11
+
12
+
* Deserialize JSON from JSON strings, base64, and compressed data
13
+
* Use JMESPath to extract and combine data recursively
14
+
15
+
## Getting started
16
+
17
+
You might have events that contains encoded JSON payloads as string, base64, or even in compressed format. It is a common use case to decode and extract them partially or fully as part of your Lambda function invocation.
18
+
19
+
Lambda Powertools also have utilities like [validation](validation.md), [idempotency](idempotency.md), or [feature flags](feature_flags.md) where you might need to extract a portion of your data before using them.
20
+
21
+
### Extracting data
22
+
23
+
You can use the `extract_data_from_envelope` function along with any [JMESPath expression](https://jmespath.org/tutorial.html){target="_blank"}.
24
+
25
+
=== "app.py"
26
+
27
+
```python hl_lines="1 7"
28
+
from aws_lambda_powertools.utilities.jmespath_utils import extract_data_from_envelope
29
+
30
+
from aws_lambda_powertools.utilities.typing import LambdaContext
You can use our built-in JMESPath functions within your expressions to do exactly that to decode JSON Strings, base64, and uncompress gzip data.
10
107
11
108
!!! info
@@ -134,33 +231,35 @@ This sample will decompress and decode base64 data, then use JMESPath pipeline e
134
231
!!! warning
135
232
This should only be used for advanced use cases where you have special formats not covered by the built-in functions.
136
233
137
-
This will **replace all provided built-in functions such as `powertools_json`, so you will no longer be able to use them**.
138
-
139
234
For special binary formats that you want to decode before applying JSON Schema validation, you can bring your own [JMESPath function](https://github.com/jmespath/jmespath.py#custom-functions){target="_blank"} and any additional option via `jmespath_options` param.
140
235
141
-
=== "custom_jmespath_function.py"
236
+
In order to keep the built-in functions from Powertools, you can subclass from `PowertoolsFunctions`:
142
237
143
-
```python hl_lines="2 6-10 14"
144
-
from aws_lambda_powertools.utilities.validation import validator
145
-
from jmespath import functions
238
+
=== "custom_jmespath_function.py"
146
239
147
-
import schemas
240
+
```python hl_lines="2-3 6-9 11 17"
241
+
from aws_lambda_powertools.utilities.jmespath_utils import (
242
+
PowertoolsFunctions, extract_data_from_envelope)
243
+
from jmespath.functions import signature
148
244
149
-
class CustomFunctions(functions.Functions):
150
245
151
-
@functions.signature({'types': ['string']})
246
+
class CustomFunctions(PowertoolsFunctions):
247
+
@signature({'types': ['string']}) # Only decode if value is a string
0 commit comments