Skip to content

Docs: JMESPath - python syntax error in custom_jmespath_function.py #1214

Closed
@michaelbrewer

Description

@michaelbrewer

Expected Behaviour

Code example in custom_jmespath_function.py should be valid python

Current Behaviour

Python example has a syntax error Expression expected

Screen Shot 2022-05-17 at 7 29 32 PM

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

  1. Go to https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/jmespath_functions/#bring-your-own-jmespath-function
  2. Copy code example for custom_jmespath_function.py
  3. Try to compile

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions