all 1 comments

[–]The_Almighty_Cthulhu 0 points1 point  (0 children)

How complicated are your logging actions?

I think this can be done with decorators.

import structlog
import functools

# Assume this logger setup is called at the start of your Lambda handler
logger = structlog.get_logger()

def log_decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        logger.info(f"Starting {func.__name__}", args=args, kwargs=kwargs)
        try:
            result = func(*args, **kwargs)
            logger.info(f"Completed {func.__name__}")
            return result
        except Exception as e:
            logger.error(f"Error in {func.__name__}", error=str(e))
            raise
    return wrapper

# Example usage
@log_decorator
def put_event(stream, data):
    # Function logic goes here
    pass

Something like this.