Aws-sam-cli: Feature Request: Specifying a temporary directory/environment variable for any unzipping/mounting in SAM local

Created on 18 Nov 2018  路  2Comments  路  Source: aws/aws-sam-cli

Description:

I'm developing on Windows, using Windows Subsystem Linux (WSL) for running anything aws-related (as well as Scala commands/etc). I have a windows native-docker server, and run docker inside WSL using export DOCKER_HOST=tcp://localhost:2375 (similar to: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly)

I'm developing a java application, the SAM client extracts the jar to the WSL /tmp directory, which isn't mountable by the Windows Docker process.

Example SAM CLI

eric@EricPeters-PC:/c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda$ echo '<!DOCTYPE html><html><head><title>HTML doc</title></head><body>Content<body></html>' | sam local invoke --docker-volume-basedir /c/Users/Eric\ Peters/IdeaProjects/ta-html-to-pdf-lambda "HtmlToPdfFunction"
2018-11-18 11:43:27 Reading invoke payload from stdin (you can also pass it from file with --event)
2018-11-18 11:43:27 Invoking ta.aws.lambda.htmltopdf.HtmlToPdfLambda::handleRequest (java8)
2018-11-18 11:43:27 Found credentials in shared credentials file: ~/.aws/credentials
2018-11-18 11:43:27 Decompressing /c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda/target/scala-2.12/html-to-pdf.jar

Fetching lambci/lambda:java8 Docker container image......
2018-11-18 11:43:43 Mounting /tmp/tmpJw834g as /var/task:ro inside runtime container
START RequestId: 8a75ec13-5a1a-45d7-89b4-15923c11986d Version: $LATEST
java.lang.ClassNotFoundException: ta.aws.lambda.htmltopdf.HtmlToPdfLambda
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)

END RequestId: 8a75ec13-5a1a-45d7-89b4-15923c11986d
REPORT RequestId: 8a75ec13-5a1a-45d7-89b4-15923c11986d  Duration: 2.73 ms       B
                        Memory Size: 128 MB     Max Memory Used: 3 MB

Proving to myself the mounting is the issue

eric@EricPeters-PC:/c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda$ mkdir /tmp/tmpKBm6IQ
eric@EricPeters-PC:/c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda$ touch /tmp/tmpKBm6IQ/test.txt
ls eric@EricPeters-PC:/c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda$ docker run -v /tmp/tmpKBm6IQ:/var/task -t -it --entrypoint  /bin/sh lambci/lambda:java8
sh-4.2$ ls -al /var/task
total 4
drwxr-xr-x 2 root root   40 Nov 18 19:25 .
drwxr-xr-x 1 root root 4096 Nov  1 21:03 ..
sh-4.2$

Proving to myself that I can mount any directory in /c/, from WSL

eric@EricPeters-PC:/c/Users/Eric Peters/IdeaProjects/ta-html-to-pdf-lambda$ docker run -v /c/tmp:/var/task -t -it  --entrypoint /bin/sh lambci/lambda:java8          
sh-4.2$ ls -al /var/task                                                                                                                                             
total 4                                                                                                                                                              /var/task:ro
drwxrwxrwx 2 root root    0 Nov 18 19:35 .                                                                                                                           
drwxr-xr-x 1 root root 4096 Nov  1 21:03 ..                                                                                                                          
-rwxr-xr-x 1 root root    0 Nov 18 19:35 foo.txt                                                                                                                     

So I need something like --docker-volume-basedir /c/Users/Eric\ Peters/IdeaProjects/ta-html-to-pdf-lambda but that will help specify a working directory for the unzip to occur.

Looks like this is happening somewhere around: https://github.com/awslabs/aws-sam-cli/blob/0e0f8159fab66cc4d4b66a0f01aa39579bc02fa2/samcli/local/lambdafn/runtime.py#L177

Most helpful comment

I figured out a work around already, adding for any other google-searchers. I simply create a /c/tmp and set TMPDIR=/c/tmp environment variable.

echo '<!DOCTYPE html><html><head><title>HTML doc</title></head><body>Content<body></html>' | TMPDIR=/c/tmp  sam local invoke "HtmlToPdfFunction"

All 2 comments

I figured out a work around already, adding for any other google-searchers. I simply create a /c/tmp and set TMPDIR=/c/tmp environment variable.

echo '<!DOCTYPE html><html><head><title>HTML doc</title></head><body>Content<body></html>' | TMPDIR=/c/tmp  sam local invoke "HtmlToPdfFunction"

Hey, I am attempting to use WSL and aws-sam-cli together. I've also got a working docker setup over WSL, but have not yet gotten my sam local start-api to properly functioning (also assuming its because of the filesystem mounting). Does your setup allow you to run the sam local start-api if you use the output of sam init --runtime python3.7 ?

Steps to try:

Initialize the sam-app
sam init --runtime python3.7
Run the local instance
cd sam-app && sam local start-api
curl the endpoint
curl http://localhost:3000/hello

Was this page helpful?
0 / 5 - 0 ratings