mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-13 09:48:47 +00:00
Start Lambda connection infrastructure
This commit is contained in:
parent
f576307e0a
commit
74eeb2a09d
1
.gitignore
vendored
1
.gitignore
vendored
@ -84,3 +84,4 @@ lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
Lambdas/Lists/src/main/resources/dbProperties.json
|
||||
|
||||
@ -24,5 +24,19 @@
|
||||
<artifactId>aws-lambda-java-log4j2</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20200518</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>1.11</maven.compiler.source>
|
||||
<maven.compiler.target>1.11</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
||||
32
Lambdas/Lists/src/main/java/DBConnector.java
Normal file
32
Lambdas/Lists/src/main/java/DBConnector.java
Normal file
@ -0,0 +1,32 @@
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DBConnector {
|
||||
|
||||
Connection connection;
|
||||
|
||||
DBConnector() throws IOException, SQLException {
|
||||
this(loadProperties("dbProperties.json"));
|
||||
}
|
||||
|
||||
DBConnector(Properties dbProperties) throws SQLException {
|
||||
System.out.println(dbProperties);
|
||||
connection = DriverManager.getConnection(dbProperties.get("url").toString(), dbProperties);
|
||||
|
||||
}
|
||||
|
||||
public static Properties loadProperties(String path) throws IOException {
|
||||
Properties toReturn = new Properties();
|
||||
String propertiesJSONString = Files.readString(Path.of(path));
|
||||
JSONObject propertiesJSON = new JSONObject(propertiesJSONString);
|
||||
propertiesJSON.keys().forEachRemaining(key -> toReturn.setProperty(key, propertiesJSON.get(key).toString()));
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,5 @@
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
@ -17,6 +19,13 @@ public class ListAdd implements RequestHandler<Map<String,Object>, String>{
|
||||
}
|
||||
System.out.println(inputMap.get("context"));
|
||||
System.out.println(contextMap.get("sub"));
|
||||
try {
|
||||
System.out.println(new DBConnector());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
4
Lambdas/Lists/src/main/java/ListAdder.java
Normal file
4
Lambdas/Lists/src/main/java/ListAdder.java
Normal file
@ -0,0 +1,4 @@
|
||||
public class ListAdder {
|
||||
|
||||
|
||||
}
|
||||
5
Lambdas/Lists/target/classes/dbProperties.json
Normal file
5
Lambdas/Lists/target/classes/dbProperties.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"url": "http://aws.com/something",
|
||||
"user": "aUser",
|
||||
"password": "aPassword"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user