1

How can you use a custom logging configuration in AWS Lambda?

Specifically, I don't want to use log4j or slf4j or ACL. I'm using java.util.logging.

I tried setting java.util.logging.config.file as an environment variable, but this didn't work as the framework expects a -D parameter.

Alex R
  • 10,320
  • 12
  • 76
  • 145

1 Answers1

2

You can use the JAVA_TOOL_OPTIONS to pass the relevant system properties into the lambda function. Take a look at https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html.

In many environments the command line is not readily accessible to start the application with necessary command-line options. This often arises with applications that use embedded VMs (meaning they use the Java Native Interface (JNI) Invocation API to start the VM), or where the startup is deeply nested in scripts. In these environments the JAVA_TOOL_OPTIONS environment variable can be useful to augment a command line.

In the AWS Lambda Console you can set the JAVA_TOOL_OPTIONS as a env variable with values like -Dfoo=bar and then this will be available as System properties in your program. Do take a look at difference between System Properties and Env Varibles.

Java system properties and environment variables

Yogesh_D
  • 14,022
  • 8
  • 31
  • 47