headers = new HashMap<>();
+
+ headers.put("Content-Type", "application/json");
+ headers.put("Access-Control-Allow-Origin", "*");
+ headers.put("Access-Control-Allow-Methods", "GET, OPTIONS");
+ headers.put("Access-Control-Allow-Headers", "*");
+
+ APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
+ .withHeaders(headers);
+ try {
+ // Read the 'address' field from the JSON post body
+ String address = JsonConfig.get().getObjectMapper().readTree(input.getBody()).get("address").asText();
+ final String pageContents = this.getPageContents(address);
+ String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
+
+ log.info("ip is {}", pageContents);
+ return response
+ .withStatusCode(200)
+ .withBody(output);
+
+ } catch (IOException e) {
+ return response
+ .withBody("{}")
+ .withStatusCode(500);
+ }
+ }
+
+ /**
+ * Helper to retrieve the contents of the given URL and return them as a string.
+ *
+ * We could also put the @Idempotent annotation here if we only wanted this sub-operation to be idempotent. Putting
+ * it on the handler, however, reduces total execution time and saves us time!
+ *
+ * @param address
+ * The URL to fetch
+ * @return The contents of the given URL
+ * @throws IOException
+ */
+ @Tracing
+ private String getPageContents(String address) throws IOException {
+ URL url = new URL(address);
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
+ return br.lines().collect(Collectors.joining(System.lineSeparator()));
+ }
+ }
+}
diff --git a/examples/powertools-examples-idempotency/sam/src/main/resources/log4j2.xml b/examples/powertools-examples-idempotency/sam/src/main/resources/log4j2.xml
new file mode 100644
index 000000000..5dede7b58
--- /dev/null
+++ b/examples/powertools-examples-idempotency/sam/src/main/resources/log4j2.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/powertools-examples-idempotency/template.yaml b/examples/powertools-examples-idempotency/sam/template.yaml
similarity index 100%
rename from examples/powertools-examples-idempotency/template.yaml
rename to examples/powertools-examples-idempotency/sam/template.yaml
diff --git a/pom.xml b/pom.xml
index 5896ffeb7..bdafe88e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,7 +101,6 @@
3.11.3
3.3.1
3.2.1
- 5.10.0
1.14.1
3.5.3
0.8.13
@@ -115,8 +114,8 @@
1.12.781
2.18.0
1.7.0
- 5.18.0
- 5.18.0
+ 5.19.1-SNAPSHOT
+ 5.19.1-SNAPSHOT
2.3.0
1.5.0
@@ -132,6 +131,21 @@
+
+
+
+ Central Portal Snapshots
+ central-portal-snapshots
+ https://central.sonatype.com/repository/maven-snapshots/
+
+ false
+
+
+ true
+
+
+
+
@@ -323,7 +337,7 @@
org.junit-pioneer
junit-pioneer
- 2.0.0
+ ${junit-pioneer.version}
test
@@ -445,6 +459,11 @@
maven-gpg-plugin
${maven-gpg-plugin.version}