I try to load properties into Properties class from a file. I would expect this solution to work: How to load property file from classpath in AWS lambda java
I have a class with few static methods and I want to use it as a Config holder. Inside it there is this line
final InputStream inputStream =
Config.class.getClass().getResourceAsStream("/application-main.properties");
and it always returns null. I downloaded the zip package that Lambda is using and the file is inside in root. Does not work nevertheless.
Anyone had similar issue?
EDIT: config file is here:
project
└───src
│ └───main
│ └───resources
│ application-main.properties
EDIT: My "temporary" workaround looks like that:
// LOAD PROPS FROM CLASSPATH...
try (InputStream is = Config.class.getResourceAsStream(fileName)) {
PROPS.load(is);
} catch (IOException|NullPointerException exc) {
// ...OR FROM FILESYSTEM
File file = new File(fileName);
try (InputStream is = new FileInputStream(file)) {
PROPS.load(is);
} catch (IOException exc2) {
throw new RuntimeException("Could not read properties file.");
}
}
During tests it reads from classpath, after deployment in AWS Lambda runtime it uses filesystem. To identify the file I used env variable:
fileName = System.getenv("LAMBDA_TASK_ROOT") + "/application-main.properties";
But I would rather just use classpath without working this around.