aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

sam local start-api bad uri for docker temp directory #445

Closed Homulvas closed 6 years ago

Homulvas commented 6 years ago

Description:

I have tried to run some example .net core code with AWS SAM today however I ran into the same error on two win10 machines that I have tried this with. Leading me to believe that it wasn't really a configuration issue as one of those machines had a nearly fresh Windows install. I had some issues before with the path specified in the template file but once I fixed that I started getting similar errors with path to the TEMP directory that is probably taken from the environment variables. Also this happens for both dotnet core and js lambdas so it's probably not related to the runtime.

Steps to reproduce the issue:

  1. Install Docker Tools and SAM cli.
  2. run sam start-api
  3. try to reach the action specified in the application template via browser.

Observed result:

sam local start-api
2018-05-30 21:45:19 Mounting LambdaTest at http://127.0.0.1:3000/hello/{input} [GET]
2018-05-30 21:45:19 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-30 21:45:19  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2018-05-30 21:46:52 Invoking LambdaTest::LambdaTest.Function::FunctionHandler (dotnetcore2.0)
2018-05-30 21:46:52 Starting new HTTP connection (1): 169.254.169.254
2018-05-30 21:46:52 Decompressing C:\Users\ignas\source\repos\LambdaTest\LambdaTest\bin\Release\netcoreapp2.0\LambdaTest.zip

Fetching lambci/lambda:dotnetcore2.0 Docker container image......
2018-05-30 21:46:54 Mounting c:\users\ignas\appdata\local\temp\tmpzcfyzi as /var/task:ro inside runtime container
[2018-05-30 21:46:54,326] ERROR in app: Exception on /hello/heeeey [GET]
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\python27\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\python27\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\python27\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\python27\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "c:\python27\lib\site-packages\samcli\local\apigw\service.py", line 161, in _request_handler
    self.lambda_runner.invoke(route.function_name, event, stdout=stdout_stream, stderr=self.stderr)
  File "c:\python27\lib\site-packages\samcli\commands\local\lib\local_lambda.py", line 80, in invoke
    stdout=stdout, stderr=stderr)
  File "c:\python27\lib\site-packages\samcli\local\lambdafn\runtime.py", line 83, in invoke
    self._container_manager.run(container)
  File "c:\python27\lib\site-packages\samcli\local\docker\manager.py", line 61, in run
    container.create()
  File "c:\python27\lib\site-packages\samcli\local\docker\container.py", line 110, in create
    real_container = self.docker_client.containers.create(self._image, **kwargs)
  File "c:\python27\lib\site-packages\docker\models\containers.py", line 824, in create
    resp = self.client.api.create_container(**create_kwargs)
  File "c:\python27\lib\site-packages\docker\api\container.py", line 410, in create_container
    return self.create_container_from_config(config, name)
  File "c:\python27\lib\site-packages\docker\api\container.py", line 421, in create_container_from_config
    return self._result(res, True)
  File "c:\python27\lib\site-packages\docker\api\client.py", line 231, in _result
    self._raise_for_status(response)
  File "c:\python27\lib\site-packages\docker\api\client.py", line 227, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "c:\python27\lib\site-packages\docker\errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("invalid volume specification: 'c:\users\ignas\appdata\local\temp\tmpzcfyzi:/var/task:ro'")
2018-05-30 21:46:54 127.0.0.1 - - [30/May/2018 21:46:54] "GET /hello/heeeey HTTP/1.1" 502 -
2018-05-30 21:46:54 127.0.0.1 - - [30/May/2018 21:46:54] "GET /favicon.ico HTTP/1.1" 403 -

Expected result:

Lambda code is invoked succesfully

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Windows 10

Output of sam --version:

SAM CLI, version 0.3.0

keremgocen commented 6 years ago

Having a similar issue on OSX with both python2.7 and python3.6 runtime inits;


2018-06-03 02:50:25 Mounting /Users/me/sam-app/hello_world/build as /var/task:ro inside runtime container
START RequestId: b3b0970a-23f3-462c-8f75-0956497dbe1f Version: $LATEST
Unable to import module 'app': No module named 'app'
END RequestId: b3b0970a-23f3-462c-8f75-0956497dbe1f
REPORT RequestId: b3b0970a-23f3-462c-8f75-0956497dbe1f Duration: 1 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 18 MB
2018-06-03 02:50:26 No Content-Type given. Defaulting to 'application/json'.
2018-06-03 02:50:26 127.0.0.1 - - [03/Jun/2018 02:50:26] "GET /hello HTTP/1.1" 200 -
2018-06-03 02:50:26 127.0.0.1 - - [03/Jun/2018 02:50:26] "GET /favicon.ico HTTP/1.1" 403 -```
jfuss commented 6 years ago

@Homulvas We had some issues with zip files, details can be found here: #389. Windows with Docker Toolbox also is having some problems, details here: #461

Since you are on Windows 10, the recommendation would be to upgrade to Windows for Docker and upgrade the CLI to the latest. This should solve everything for you.

@keremgocen Upgrade your CLI if you are on version 0.3.0. If that isn't the issue, then make sure you CodeUri is point to a directory where all your code and dependencies are installed to. There is a really good example of how you can setup python if you run sam init --runtime python and follow the README that is generated in the folder.

Closing since this is a duplicate of a couple issues we have resolved (#461 is not resolved but upgrading to Windows for Docker from Docker Toolbox will work).