Closed
Description
- Framework version: 1.1
- Implementations: Spark
Scenario
Very basic "Hello World" app.
Folder Structure
|--src
|--main
|--java
SparkResources.java
StreamLambdaHandler.java
pom.xml
sam.yaml
SparkResources
import static spark.Spark.*;
public class SparkResources {
public static void defineResources() {
get("/", (req, res) -> "This is root page");
get("/example", (req, res) -> "This is example page");
}
}
Expected behavior
- User should be able to see "This is root page" when navigates to the root url "/"
- User should be able to see "This is example page" when navigates to the "/example"
Actual behavior
- User sees "404 page not found" when navigates to the root url "/"
- User sees "This is example page" when navigates to the "/example" (this one works correctly)
Steps to reproduce
- Clone the repo
[email protected]:sergeome/java-spark-aws-lambda.git
mvn clean package
sam local start-api --template sam.yaml
- Navigate to both Urls.
Full log output
For the first time user navigates to the "/", for the second time user navigates to the "/example"
$ sam local start-api --template sam.yaml
2018/05/22 21:18:06 Connected to Docker 1.37
2018/05/22 21:18:06 Fetching lambci/lambda:java8 image for java8 runtime...
java8: Pulling from lambci/lambda
Digest: sha256:6d8025500d2b06054470cb787d54d5bda8f1362fdaf0079510414947cf8cc0a1
Status: Image is up to date for lambci/lambda:java8
Mounting StreamLambdaHandler::handleRequest (java8) at http://127.0.0.1:3000/{proxy+} [OPTIONS GET HEAD POST PUT DELETE PATCH]
You can now browse to the above endpoints to invoke your functions.
You do not need to restart/reload SAM CLI while working on your functions,
changes will be reflected instantly/automatically. You only need to restart
SAM CLI if you update your AWS SAM template.
2018/05/22 21:18:13 Invoking StreamLambdaHandler::handleRequest (java8)
2018/05/22 21:18:13 Decompressing spark-cloud/target/spark-cloud-1.0.jar
2018/05/22 21:18:13 Mounting /private/var/folders/96/ykvzpbyx6sn6srvd5j48xmnm0000gn/T/aws-sam-local-1527041893269176000 as /var/task:ro inside runtime container
[main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Starting Lambda Container Handler
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Spark called configureWebSockets. However, web sockets are not supported
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Starting Spark server, ignoring port and host
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Called join method, nothing to do here since Lambda only runs a single event per container
START RequestId: 4f3421ae-087e-435b-b8da-8d8007294676 Version: $LATEST
[main] INFO spark.http.matching.MatcherFilter - The requested route [/favicon.ico] has not been mapped in Spark for Accept: [image/webp,image/apng,image/*,*/*;q=0.8]
[main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - 127.0.0.1:51053 - [01/01/1970:00:00:00Z] "GET /favicon.ico null" 404 48 "-" "-" combined
END RequestId: 4f3421ae-087e-435b-b8da-8d8007294676
REPORT RequestId: 4f3421ae-087e-435b-b8da-8d8007294676 Duration: 160.74 ms Billed Duration: 200 ms Memory Size: 512 MB Max Memory Used: 2 MB
2018/05/22 21:18:20 Invoking StreamLambdaHandler::handleRequest (java8)
2018/05/22 21:18:20 Decompressing spark-cloud/target/spark-cloud-1.0.jar
2018/05/22 21:18:20 Mounting /private/var/folders/96/ykvzpbyx6sn6srvd5j48xmnm0000gn/T/aws-sam-local-1527041900174297000 as /var/task:ro inside runtime container
[main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Starting Lambda Container Handler
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Spark called configureWebSockets. However, web sockets are not supported
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Starting Spark server, ignoring port and host
[Thread-0] INFO com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer - Called join method, nothing to do here since Lambda only runs a single event per container
START RequestId: 5031b3aa-7565-4a63-bde6-451978f77419 Version: $LATEST
[main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - 127.0.0.1:51053 - [01/01/1970:00:00:00Z] "GET /example null" 200 20 "-" "-" combined
END RequestId: 5031b3aa-7565-4a63-bde6-451978f77419
REPORT RequestId: 5031b3aa-7565-4a63-bde6-451978f77419 Duration: 157.26 ms Billed Duration: 200 ms Memory Size: 512 MB Max Memory Used: 2 MB