How to load property file from classpath in AWS lambda java

妖精的绣舞 提交于 2019-12-04 03:33:07

You are only one character off. Here's a working example that I have to do the same thing:

InputStream is = DBConfiguartion.class.getResourceAsStream("/lambda.properties");
Properties properties = new Properties();
properties.load(is);

This works with the following maven file structure when building the deployment jar:

  • project
  • project/src/main/java
  • project/src/main/java/com/something/DBConfiguartion.java -
  • project/src/main/resources
  • project/src/main/resources/lambda.properties

As you want to load a properties file you can use the ResourceBundle to load the properties.

String version = ResourceBundle.getBundle("lambda").getString("version");

It's not the same as loading file as an InputStream, but this worked for me. In a maven project the file would need to be located at:

  • project/src/main/resources/lambda.properties

I have a simple Hello-World Lambda which reads the current version from a properties file on github.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!