Skip to content

Bug: Powertools JMESPath functions don't work in @logger.inject_lambda_context(correlation_id_path=...) #3381

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

Closed
heitorlessa opened this issue Nov 21, 2023 · 2 comments
Assignees
Labels
bug Something isn't working logger

Comments

@heitorlessa
Copy link
Contributor

Expected Behaviour

Able to deserialize JSON string and extract given field

Current Behaviour

UnknownFunctionError exception by JMESPath when using any of the Powertools custom functions: https://docs.powertools.aws.dev/lambda/python/latest/utilities/jmespath_functions/#extracting-data

Code snippet

# Extract Event IDs from EventBridge and set as correlation ID (list value as there could be N events)
@logger.inject_lambda_context(correlation_id_path="Records[*].powertools_json(body).id")
@metrics.log_metrics(capture_cold_start_metric=True)
@tracer.capture_lambda_handler
def lambda_handler(event, context: LambdaContext):
    return True

Possible Solution

Use jmespath_utils instead of jmespath.search like the rest of Powertools utilities (Logger, Idempotency, Validation).

Steps to Reproduce

Call this function with the following event:

{
    "Records": [
        {
            "messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
            "receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
            "body": "{'id': '6a7e8feb-b491-4cf7-a9f1-bf3703467718'}",
            "attributes": {
                "ApproximateReceiveCount": "1",
                "SentTimestamp": "1545082649183",
                "SenderId": "AIDAIENQZJOLO23YVJ4VO",
                "ApproximateFirstReceiveTimestamp": "1545082649185"
            },
            "messageAttributes": {
                "testAttr": {"stringValue": "100", "binaryValue": "base64Str", "dataType": "Number"}
            },
            "md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
            "eventSource": "aws:sqs",
            "eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
            "awsRegion": "us-east-2"
        }
    ]
},

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.11

Packaging format used

PyPi

Debugging logs

No response

@heitorlessa heitorlessa added bug Something isn't working triage Pending triage from maintainers labels Nov 21, 2023
@heitorlessa heitorlessa added logger and removed triage Pending triage from maintainers labels Nov 21, 2023
@heitorlessa heitorlessa self-assigned this Nov 21, 2023
@heitorlessa heitorlessa moved this from Triage to Working on it in Powertools for AWS Lambda (Python) Nov 21, 2023
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2023
@heitorlessa heitorlessa moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Nov 21, 2023
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

Copy link
Contributor

This is now released under 2.27.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2023
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logger
Projects
Status: Shipped
Development

No branches or pull requests

1 participant