Code Monkey home page Code Monkey logo

Comments (9)

leandrodamascena avatar leandrodamascena commented on August 9, 2024 1

Looking at this now..

from powertools-lambda-python.

boring-cyborg avatar boring-cyborg commented on August 9, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

from powertools-lambda-python.

leandrodamascena avatar leandrodamascena commented on August 9, 2024

Hi @Mavtti! Thanks for opening this issue to report a possible bug. Just to confirm my suspicion: your SuggestionPayload doesn't extend from BaseModel, right? Here we parse the envelope using the provided Model (SuggestionPayload) and both (Model and Envelope) must extend from the BaseModel, otherwise the parse will fail.

However, I think there is room for us to improve our error message, as it leads us to believe that it is a problem with the Envelope and not the Model.

What do you think about sending a PR and improving the error message?

Thanks


Example of code that works

from aws_lambda_powertools.utilities.parser import envelopes
from aws_lambda_powertools.utilities.parser.models import KinesisDataStreamModel
from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.typing import LambdaContext

from pydantic import BaseModel

class SuggestionPayload(BaseModel):
    message: str
    username: str


@event_parser(model=SuggestionPayload, envelope=envelopes.KinesisDataStreamEnvelope)
def lambda_handler(document_events: KinesisDataStreamModel, _: LambdaContext):
    print(document_events)

Payload

{
  "Records": [
    {
      "kinesis": {
        "kinesisSchemaVersion": "1.0",
        "partitionKey": "1",
        "sequenceNumber": "49590338271490256608559692538361571095921575989136588898",
        "data": "eyJtZXNzYWdlIjogInRlc3QgbWVzc2FnZSIsICJ1c2VybmFtZSI6ICJ0ZXN0In0=",
        "approximateArrivalTimestamp": 1545084650.987
      },
      "eventSource": "aws:kinesis",
      "eventVersion": "1.0",
      "eventID": "shardId-000000000006:49590338271490256608559692538361571095921575989136588898",
      "eventName": "aws:kinesis:record",
      "invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role",
      "awsRegion": "us-east-2",
      "eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream"
    }
  ]
}

data field decoded

echo eyJtZXNzYWdlIjogInRlc3QgbWVzc2FnZSIsICJ1c2VybmFtZSI6ICJ0ZXN0In0= |base64 -di
{"message": "test message", "username": "test"}

from powertools-lambda-python.

Mavtti avatar Mavtti commented on August 9, 2024

Hey @leandrodamascena thank for looking into it.

Actually my SuggestionPayload does inherit from BaseModel.

Here is a sample:

from pydantic import BaseModel

from .document import Document


class SuggestionPayload(BaseModel):
    arrived_at: Optional[str | int | float]
    data: Document
    operation: str

And the subclass Document also inherit from BaseModel.

I've tried using:
KinesisDataStreamEnvelope().parse(...) instead with no issue.

from powertools-lambda-python.

leandrodamascena avatar leandrodamascena commented on August 9, 2024

Hi @Mavtti! Sorry to hear this, but in all my attempts here I could not reproduce the error. I am interested in understanding what is going wrong and fixing it.
Can you please send me a payload that you are using to invoke your Lambda? Please remove any sensitive data.

Thank you

from powertools-lambda-python.

Mavtti avatar Mavtti commented on August 9, 2024

Hey @leandrodamascena in the end I've been able to reproduce on my side.

You were right on the displayed error message, it hides the real issue. For my case it came from an AttributeError on the SuggestionPayload class.

And this AttributeError was catched by the try/except. If it was any other error it would have been more explicit.

Thx for the help.

from powertools-lambda-python.

leandrodamascena avatar leandrodamascena commented on August 9, 2024

Hey @Mavtti! Nice to hear you could figure out this. I sent a PullRequest to improve the error message and make it more clear.

Thanks again for taking the time to help us improve the developer experience. I will give you credits when I release a version with this fix.

from powertools-lambda-python.

github-actions avatar github-actions commented on August 9, 2024

⚠️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.

from powertools-lambda-python.

github-actions avatar github-actions commented on August 9, 2024

This is now released under 2.31.0 version!

from powertools-lambda-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.