Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I have written AWS lambda function in that I want to read database connection details from the property file and which in my classpath, but I am not able to load that file. Here is my code:

InputStream input = DBConfiguartion.class.getResourceAsStream("appsettings"); 

        Reader r = new InputStreamReader(input, "UTF-8");

        Properties prop = new Properties();

        prop.load(r);

If I run this code through normal java console application that time it is working, but whenever I run it as AWS lambda function then InputStream is coming null.

1 Answer

0 votes
by (44.4k points)

This works:

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

Properties properties = new Properties();

properties.load(is);

The maven file structure should be like this for 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

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...