diff --git a/aws-lambda/pom.xml b/aws-lambda/pom.xml new file mode 100644 index 0000000000..c02d9d59dd --- /dev/null +++ b/aws-lambda/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + com.baeldung + aws-lambda + 0.1.0-SNAPSHOT + jar + aws-lambda + + + + com.amazonaws + aws-lambda-java-core + 1.1.0 + + + + commons-io + commons-io + 2.5 + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + + + + package + + shade + + + + + + + \ No newline at end of file diff --git a/aws-lambda/src/main/java/com/baeldung/LambdaMethodHandler.java b/aws-lambda/src/main/java/com/baeldung/LambdaMethodHandler.java new file mode 100644 index 0000000000..6cce694912 --- /dev/null +++ b/aws-lambda/src/main/java/com/baeldung/LambdaMethodHandler.java @@ -0,0 +1,10 @@ +package com.baeldung; + +import com.amazonaws.services.lambda.runtime.Context; + +public class LambdaMethodHandler { + public String handleRequest(String input, Context context) { + context.getLogger().log("Input: " + input); + return "Hello World - " + input; + } +} diff --git a/aws-lambda/src/main/java/com/baeldung/LambdaRequestHandler.java b/aws-lambda/src/main/java/com/baeldung/LambdaRequestHandler.java new file mode 100644 index 0000000000..37f114db25 --- /dev/null +++ b/aws-lambda/src/main/java/com/baeldung/LambdaRequestHandler.java @@ -0,0 +1,11 @@ +package com.baeldung; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; + +public class LambdaRequestHandler implements RequestHandler { + public String handleRequest(String input, Context context) { + context.getLogger().log("Input: " + input); + return "Hello World - " + input; + } +} diff --git a/aws-lambda/src/main/java/com/baeldung/LambdaRequestStreamHandler.java b/aws-lambda/src/main/java/com/baeldung/LambdaRequestStreamHandler.java new file mode 100644 index 0000000000..aba65628ad --- /dev/null +++ b/aws-lambda/src/main/java/com/baeldung/LambdaRequestStreamHandler.java @@ -0,0 +1,18 @@ +package com.baeldung; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.lambda.runtime.RequestStreamHandler; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class LambdaRequestStreamHandler implements RequestStreamHandler { + + public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { + String input = IOUtils.toString(inputStream, "UTF-8"); + outputStream.write(("Hello World - " + input).getBytes()); + } +}