Skip to content

Documentation: How correctly log AWS Lambda event with lambda powertools when using @event_source #1773

Closed
@heitorlessa

Description

@heitorlessa

Discussed in #1769

Originally posted by macdrorepo December 9, 2022

I've started using lambda power-tools for lambda. Currently my code looks like:

@event_source(data_class=SNSEvent)
@LOGGER.inject_lambda_context(log_event=True)
def handler(event: SNSEvent, context: LambdaContext) -> None:  # pylint: disable=W0613
    """Lambda function invoked by Image builder SNS topic, putting Image
    builder ami-id in parameter store.
    :param event: SNS message containing Image Builder build results
    :return:
    """
    LOGGER.debug(f"Event: {event}") //logging event
    for record in event.records:
        message = record.sns.message
        LOGGER.info(f"Message: {message}")
        process_sns_event(message)
        return None

In line with comment I want to log what actually is lambda getting at beginning. As for now in cloud watch I'm getting entries like: Event: <aws_lambda_powertools.utilities.data_classes.sns_event.SNSEvent object at 0x7f9bbd36a0> or Event: <generator object SNSEvent.records at 0x7facfb6510> after updating powertools version to latest.

I'm confused what should I do to log just event json. Can any one point me out what should I do? (I'm rather beginner as can seen).

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationevent_sourcesEvent Source Data Class utilityparserParser (Pydantic) utility

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions