Comments (9)
Looking at this now..
from powertools-lambda-python.
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.
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.
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.
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.
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.
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.
⚠️ 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.
This is now released under 2.31.0 version!
from powertools-lambda-python.
Related Issues (20)
- List intersection action for conditions in feature flags HOT 16
- Feature request: Expand DataMasking utility to encrypt list, set, and tuple data type for better user excperience HOT 1
- Feature request: openAPI - support for top level tags metadata HOT 5
- Bug: openAPI generation - operation requestBody description only on schema output, not at higher level needed for html HOT 6
- Feature Request: ability to define additional response models in OpenAPI HOT 5
- Feature request: Add Canada - Calgary region to the Lambda Layers Deployment HOT 3
- Bug: AppSyncResolver Context not set in tests HOT 5
- Bug: Swagger UI doesn't load : Loading... with Uncaught SyntaxError HOT 9
- Docs: Invalid return type in middleware example HOT 4
- Feature request: Add ability to download OpenAPI spec HOT 4
- Feature request: Add support for S3 Batch Operations event HOT 7
- Static typing: Untyped event_source decorator with mypy --strict HOT 2
- Bug: Repository analytics is broken and not being marked as failling HOT 2
- Maintenance: Remove dev dependencies locked to Pydantic v1 in the Pydantic v2 workflow HOT 2
- Feature request: Publish AWS Lambda layers under /aws/service/list HOT 2
- [I Made This]: Creating a serverless API using AWS Lambda Powertools and CDK HOT 6
- bug: Swagger UI is breaking with certain characters HOT 5
- Feature: Event handler Swagger doesnt add 422 response to openapi when adding custom responses HOT 3
- Bug: Can't install with pyndantic >2.0 (despite documentation saying otherwise) HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powertools-lambda-python.