amazon web services - AWS Lambda Java how to read properties file -
i try load properties properties class file. expect solution work: how load property file classpath in aws lambda java
i have class few static methods , want use config holder. inside there line
final inputstream inputstream = config.class.getclass().getresourceasstream("/application-main.properties");
and returns null. downloaded zip package lambda using , file inside in root. not work nevertheless.
anyone had similar issue?
edit: config file here:
project └───src │ └───main │ └───resources │ application-main.properties
edit: "temporary" workaround looks that:
// load props classpath... try (inputstream = config.class.getresourceasstream(filename)) { props.load(is); } catch (ioexception|nullpointerexception exc) { // ...or filesystem file file = new file(filename); try (inputstream = new fileinputstream(file)) { props.load(is); } catch (ioexception exc2) { throw new runtimeexception("could not read properties file."); } }
during tests reads classpath, after deployment in aws lambda runtime uses filesystem. identify file used env variable:
filename = system.getenv("lambda_task_root") + "/application-main.properties";
but rather use classpath without working around.
let's assume have following folder structure:
project └───src │ └───main │ └───resources │ config.properties
and lambda handler:
classloader loader = config.class.getclassloader(); inputstream input = loader.getresourceasstream("config.properties");
that may work...
Comments
Post a Comment