Goal
Set system properties in an AWS Lambda Function written in Java
Description
Lately, I have been implementing my first AWS Lambda functions in Java and I had the need to specify some System properties for this lambda function (accessible through System.getProperty("myprop") and not System.getenv("myprop")). This recipe explains what one must do in order to make this possible.
How to
Since it is AWS that starts the JVM and it does not provide any configuration options to set what options should be used on startup, the trick is to use the JAVA_TOOL_OPTIONS environment variable.
So, if we have a Lambda function that needs to access a System property named “foo”, as in the following code:
public class MyHandler implements RequestHandler {
public MyOutput handleRequest(final MyInput input, Context context) {
String foo = System.getProperty("foo");
...
}
}
we would just need to specify the following as one of the lambda’s environment variables:
JAVA_TOOL_OPTIONS="-Dfoo=foo"
Explanations
The environment variable JAVA_TOOL_OPTIONS is a very useful way to augment a command line in environments, such as the one in AWS Lambdas, that do not make it readily accessible to start the application with necessary command-line options. By using that environment variable, we make it possible to add that information independently of the way that the JVM was started.

Thank you! This was a great help. π