Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michaelbrewer opened this issue May 18, 2022 · 1 comment
Closed
Labels
documentation Improvements or additions to documentation

Comments

@michaelbrewer
Copy link
Contributor

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
@michaelbrewer michaelbrewer added bug Something isn't working triage Pending triage from maintainers labels May 18, 2022
@michaelbrewer michaelbrewer changed the title Bug: JMESPath, python syntax error in custom_jmespath_function.py Bug: JMESPath - python syntax error in custom_jmespath_function.py May 18, 2022
@sthulb sthulb changed the title Bug: JMESPath - python syntax error in custom_jmespath_function.py Docs: JMESPath - python syntax error in custom_jmespath_function.py May 18, 2022
@heitorlessa heitorlessa added documentation Improvements or additions to documentation and removed bug Something isn't working labels May 20, 2022
@sthulb sthulb closed this as completed Jun 14, 2022
@github-actions
Copy link
Contributor

Comments on closed issues are hard for our team to see.

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants