Skip to content

Logger: log_event does not serialize classes #947

Closed
@kishaningithub

Description

@kishaningithub

What were you trying to accomplish?
I was trying to log the received S3 event. Please note that i am using the data classes present in this library for reading the event

@event_source(data_class=S3Event)
@log.inject_lambda_context(
    log_event=True
)
def lambda_handler(event: S3Event, context: LambdaContext):

Expected Behavior

The logged event should have all the information from the S3 event

Current Behavior

This is the output i get in the log (trimmed)

{
    "level": "INFO",
    "message": "<aws_lambda_powertools.utilities.data_classes.s3_event.S3Event object at 0x7f0be7efb2b0>",
    "timestamp": "2022-01-11 06:36:20,111+0000",
}

It looks to be that it was unable to properly represent the S3Event object as a string

Possible Solution

Implement repr and str methods in S3Event class or in the parent DictWrapper class

Steps to Reproduce (for bugs)

  1. Implement a lambda which receives and S3 event like the following
@event_source(data_class=S3Event)
@log.inject_lambda_context(
    log_event=True
)
def lambda_handler(event: S3Event, context: LambdaContext):
   pass
  1. Setup the lambda trigger as S3 object creation event
  2. Upload a file in the S3 bucket where trigger is setup
  3. See the logs in cloud watch

Environment

  • Powertools version used: 1.24.0
  • Packaging format (Layers, PyPi): PyPi
  • AWS Lambda function runtime: 3.9
  • Debugging logs

How to enable debug mode**

# paste logs here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions