Closed
Description
Expected Behaviour
Code example in custom_jmespath_function.py
should be valid python
Current Behaviour
Python example has a syntax error Expression expected
Code snippet
from aws_lambda_powertools.utilities.jmespath_utils import (
PowertoolsFunctions, extract_data_from_envelope)
from jmespath.functions import signature
class CustomFunctions(PowertoolsFunctions):
@signature({'types': ['string']}) # Only decode if value is a string
def _func_special_decoder(self, s):
return my_custom_decoder_logic(s)
custom_jmespath_options = {"custom_functions": CustomFunctions()}
def handler(event, context):
# use the custom name after `_func_`
extract_data_from_envelope(data=event,
envelope="special_decoder(body)",
jmespath_options=**custom_jmespath_options)
...
Possible Solution
Fix code example like in PR #1120 , a deployed example https://gyft.github.io/aws-lambda-powertools-python/latest/utilities/jmespath_functions/#bring-your-own-jmespath-function
from jmespath.functions import signature
from aws_lambda_powertools.utilities.jmespath_utils import PowertoolsFunctions, extract_data_from_envelope
class CustomFunctions(PowertoolsFunctions):
@signature({"types": ["string"]}) # Only decode if value is a string
def _func_special_decoder(self, s):
return my_custom_decoder_logic(s)
custom_jmespath_options = {"custom_functions": CustomFunctions()}
def handler(event, context):
# use the custom name after `_func_`
extract_data_from_envelope(
data=event,
envelope="special_decoder(body)",
jmespath_options=custom_jmespath_options,
)
...
Steps to Reproduce
- Go to https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/jmespath_functions/#bring-your-own-jmespath-function
- Copy code example for
custom_jmespath_function.py
- Try to compile
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
N/A