Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendation for Logging data in AWS Lambda

AWS lambda currently supports two ways for logging, when Lambda function written in Java.

  • log4j
  • LambdaLogger

I want to know if is their any advantage of using one logging scheme over other.

Thanks!

like image 241
Mayur Dabhi Avatar asked May 09 '16 09:05

Mayur Dabhi


People also ask

How do I log a lambda function in AWS Lambda?

AWS Lambda Function Logging in Python. Your Lambda function comes with a CloudWatch Logs log group, with a log stream for each instance of your function. The runtime sends details about each invocation to the log stream, and relays logs and other output from your function's code.

What is Cloudwatch Logs for AWS Lambda?

It also helps you log and monitor your Lambda functions for performance optimization and diagnosing application-level issues. Lambda automatically streams standard output and standard error messages from a Lambda function to CloudWatch Logs, without requiring logging drivers.

What are the best practices for logging lambda functions?

Another best practice is to set the log output level by using a variable and adjust it based on the environment and your requirements. Your Lambda function's code, in addition to the libraries used, could output a large amount of log data depending on the log output level. This can impact your logging costs and affect performance.

What is a Lambda log stream?

A separate log stream is created in the log group for each Lambda function instance. Lambda has a standard naming convention for log streams that uses a YYYY/MM/DD/ [<FunctionVersion>]<InstanceId> format. The InstanceId is generated by AWS to identify the Lambda function instance.


2 Answers

What I understood from Aws Lambda Java Logging and searching around net is

  • Log4J

    • pros: you can customize logs(using log4j.properties).
    • cons: it increase the size of your jar/zip as you add more dependency to your project
  • LambdaLogger

    • pros: it saves memory as it is already embeded on your dependencies
    • cons: it can't be customizable

I hope that it helps!

like image 190
user1321759 Avatar answered Oct 19 '22 22:10

user1321759


In my opinion to keep it simple.

1. Assume you have an application project in maven where there will be multiple maven modules. You won't be passing context.getLogger() OR context argument every time you call some other module's implementation.

2. If you have a single handler function with no modules and multiple classes. In this case, you can start your AWS Lambda handler function code and get the context.getLogger() to get Lambda logger.

For more info : http://docs.aws.amazon.com/lambda/latest/dg/programming-model-v2.html

like image 41
hungrytolearn Avatar answered Oct 19 '22 23:10

hungrytolearn