We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Code examples for Pydantic integration should be validate an not have missing imports or reference undefined class.
All of the code examples have missing imports or reference class that one exist
Kinesis Data Streams example
Kinesis Data Streams
DynamoDB Streams example
DynamoDB Streams
import json from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor from aws_lambda_powertools.utilities.parser.models import SqsRecordModel from aws_lambda_powertools.utilities.typing import LambdaContext class Order(BaseModel): item: dict class OrderSqsRecord(SqsRecordModel): body: Order # auto transform json string # so Pydantic can auto-initialize nested Order model @validator("body", pre=True) def transform_body_to_dict(cls, value: str): return json.loads(value) processor = BatchProcessor(event_type=EventType.SQS, model=OrderSqsRecord) tracer = Tracer() logger = Logger() @tracer.capture_method def record_handler(record: OrderSqsRecord): return record.body.item @logger.inject_lambda_context @tracer.capture_lambda_handler @batch_processor(record_handler=record_handler, processor=processor) def lambda_handler(event, context: LambdaContext): return processor.response()
Fix missing imports and validate code examples against a compiler, a fix PR exists here: #1114 and deployed https://gyft.github.io/aws-lambda-powertools-python/latest/utilities/batch/#pydantic-integration
Fixed example
import json from aws_lambda_powertools import Logger, Tracer from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor from aws_lambda_powertools.utilities.parser import BaseModel, validator from aws_lambda_powertools.utilities.parser.models import SqsRecordModel from aws_lambda_powertools.utilities.typing import LambdaContext class Order(BaseModel): item: dict class OrderSqsRecord(SqsRecordModel): body: Order # auto transform json string # so Pydantic can auto-initialize nested Order model @validator("body", pre=True) def transform_body_to_dict(cls, value: str): return json.loads(value) processor = BatchProcessor(event_type=EventType.SQS, model=OrderSqsRecord) tracer = Tracer() logger = Logger() @tracer.capture_method def record_handler(record: OrderSqsRecord): return record.body.item @logger.inject_lambda_context @tracer.capture_lambda_handler @batch_processor(record_handler=record_handler, processor=processor) def lambda_handler(event, context: LambdaContext): return processor.response()
latest
3.9
PyPi
N/A
The text was updated successfully, but these errors were encountered:
Comments on closed issues are hard for our team to see.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Expected Behaviour
Code examples for Pydantic integration should be validate an not have missing imports or reference undefined class.
Current Behaviour
All of the code examples have missing imports or reference class that one exist
Kinesis Data Streams
exampleDynamoDB Streams
exampleCode snippet
Possible Solution
Fix missing imports and validate code examples against a compiler, a fix PR exists here: #1114 and deployed https://gyft.github.io/aws-lambda-powertools-python/latest/utilities/batch/#pydantic-integration
Fixed example
Steps to Reproduce
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: