Our SAM template references a zip file CodeUri as our stuff is compiled prior to deployment but aws-sam-local doesn't handle this very well. Ie CodeUri: ../target/lambda.zip
Error:
Could not invoke function: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/home/myuser/lambda-code/target/lambda.zip\\\" to rootfs \\\"/var/lib/docker/overlay2/ef772db7acbb72271b6e24b4af6937a30adfa608d595aeae6fa2411f586d11fd/merged\\\" at \\\"/var/lib/docker/overlay2/ef772db7acbb72271b6e24b4af6937a30adfa608d595aeae6fa2411f586d11fd/merged/var/task\\\" caused \\\"not a directory\\\"\""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Agreed, this is a very common use case and we should support it.
Looking forward to this feature as well!
Working on this at the moment.
Should be done later today if all goes well.
This is now implemented by pull request #75 (automatic unzipping of packaged archives such as JAR/ZIP).
With the new version:
Resources:
PetStoreFunction:
Type: AWS::Serverless::Function
Properties:
Handler: com.amazonaws.serverless.sample.jersey.LambdaHandler::handleRequest
Runtime: java8
CodeUri: target/serverless-jersey-example-1.0-SNAPSHOT.jar
... snip ...
$ git clone https://github.com/awslabs/aws-serverless-java-container
$ cd aws-serverless-java-container/samples/jersey/pet-store
$ mvn package
$ sam local start-api -t sam.yaml
2017/08/18 15:25:00 Connected to Docker 1.30
2017/08/18 15:25:00 Successfully parsed sam.yaml (version 2010-09-09)
2017/08/18 15:25:00 Fetching lambci/lambda:java8 image for java8 runtime...
java8: Pulling from lambci/lambda
Digest: sha256:668979530863a155b52533947e782fe164908eda2d6c5741317511bfa036d8cf
Status: Image is up to date for lambci/lambda:java8
Mounting com.amazonaws.serverless.sample.jersey.LambdaHandler::handleRequest (java8) at http://127.0.0.1:3000/{proxy+} [OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT]
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.
2017/08/18 15:26:17 Invoking com.amazonaws.serverless.sample.jersey.LambdaHandler::handleRequest (java8)
2017/08/18 15:26:17 Decompressing serverless-jersey-example-1.0-SNAPSHOT.jar into runtime container...
log4j:WARN No appenders could be found for logger (com.amazonaws.serverless.proxy.internal.LambdaContainerHandler).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
START RequestId: 0aee9bbe-79d0-480a-8efb-9dfd35ca68b8 Version: $LATEST
END RequestId: 0aee9bbe-79d0-480a-8efb-9dfd35ca68b8
REPORT RequestId: 0aee9bbe-79d0-480a-8efb-9dfd35ca68b8 Duration: 454.63 ms Billed Duration: 500 ms Memory Size: 512 MB Max Memory Used: 13 MB
and the HTTP response from http://localhost:3000/pets
[{"id":"d2d77c29-4426-4c1c-9445-15367993db21","breed":"Jack Russell Terrier","name":"Teddy","dateOfBirth":1448375182603},{"id":"918c5a08-abb2-43fc-a9e5-40ab4a9f538d","breed":"Beagle","name":"Max","dateOfBirth":1304605582603},{"id":"4416e7df-40e0-4695-b622-4c64336a55eb","breed":"Afghan Hound","name":"Bear","dateOfBirth":1196778382604},{"id":"046f0a53-e851-4105-b024-411cead3d2a7","breed":"Beagle","name":"Jack\t","dateOfBirth":1011450382604},{"id":"9078d215-7bcc-4534-9e2a-d3aaf6a45ef6","breed":"Dalmatian","name":"Bella","dateOfBirth":1309098382604},{"id":"9911779b-398f-4f6a-b4ae-da3b531d3e0d","breed":"Jack Russell Terrier","name":"Maggie","dateOfBirth":1093184782604},{"id":"a6838c72-aabc-45bf-93cd-b08157493c22","breed":"Bloodhound","name":"Ginger","dateOfBirth":1331130382604},{"id":"a420d1cc-ba29-4731-87a8-64a0a3fc9eaa","breed":"Beagle","name":"Princess","dateOfBirth":1035901582604},{"id":"5decb878-15b4-4c01-8bcf-33bde8bbbcf7","breed":"Dalmatian","name":"Roxy","dateOfBirth":1122301582604},{"id":"22a64d5f-e20c-42f8-9745-2357ded83add","breed":"Afghan Hound","name":"Lola","dateOfBirth":1202135182604}]
This will be included in our next release. I don't have an exact date right now, but it won't be long.
Most helpful comment
This is now implemented by pull request #75 (automatic unzipping of packaged archives such as JAR/ZIP).
With the new version:
and the HTTP response from http://localhost:3000/pets
This will be included in our next release. I don't have an exact date right now, but it won't be long.