Skip to content

Commit d7687c9

Browse files
committed
feat: add powertools_base64 custom fn
1 parent acc3b83 commit d7687c9

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

aws_lambda_powertools/utilities/validation/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from jmespath.exceptions import LexerError
77

88
from .exceptions import InvalidEnvelopeExpressionError, InvalidSchemaError, SchemaValidationError
9-
from .jmespath_functions import PowertoolsJson
9+
from .jmespath_functions import PowertoolsFunctions
1010

1111
logger = logging.getLogger(__name__)
1212

@@ -23,7 +23,7 @@ def validate_data_against_schema(data: Dict, schema: Dict):
2323

2424
def unwrap_event_from_envelope(data: Dict, envelope: str, jmespath_options: Dict):
2525
if not jmespath_options:
26-
jmespath_options = {"custom_functions": PowertoolsJson()}
26+
jmespath_options = {"custom_functions": PowertoolsFunctions()}
2727

2828
try:
2929
logger.debug(f"Envelope detected: {envelope}. JMESPath options: {jmespath_options}")
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Built-in envelopes"""
22

3-
API_GATEWAY_REST = "powertools(body)"
3+
API_GATEWAY_REST = "powertools_json(body)"
44
API_GATEWAY_HTTP = API_GATEWAY_REST
55
SQS = "Records[*].body"
66
SNS = "Records[0].Sns.Message"
77
EVENTBRIDGE = "detail"
88
CLOUDWATCH_EVENTS_SCHEDULED = EVENTBRIDGE
9+
KINESIS_DATA_STREAM = "Records[*].kinesis.powertools_base64(data) | powertools_json(@)"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import base64
12
import json
23

34
import jmespath
45

56

6-
class PowertoolsJson(jmespath.functions.Functions):
7+
class PowertoolsFunctions(jmespath.functions.Functions):
78
@jmespath.functions.signature({"types": ["string"]})
89
def _func_powertools_json(self, value):
910
return json.loads(value)
11+
12+
@jmespath.functions.signature({"types": ["string"]})
13+
def _func_powertools_base64(self, value):
14+
return base64.b64decode(value).decode()

0 commit comments

Comments
 (0)