Class AWSLambdaLogger

  • All Implemented Interfaces:
    Serializable, Logger

    public class AWSLambdaLogger
    extends Object
    implements Logger, Serializable
    An SLF4J Logger implementation for AWS Lambda.

    This is common with SLF4J Simple but supports MDC. You could put AWS request ID to MDC then it is printed out in start every log line:

    
       @Override
       public String handleRequest(Map<String, Object> input, Context context) {
         MDC.put("AWS_REQUEST_ID", context.getAwsRequestId());
         ...
         logger.info("info message");
         ...
         return "done";
       }
     
    The log:
    
     START RequestId: cc4eb5aa-66b4-42fc-b27a-138bd672b38a Version: $LATEST
     cc4eb5aa-66b4-42fc-b27a-138bd672b38a INFO io.github.vitalijr2.slf4j_demo.BotHandler - info message
     END RequestId: cc4eb5aa-66b4-42fc-b27a-138bd672b38a
     
    See Also:
    AWSLambdaLogger's configuration, Serialized Form