Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local start-api does not install requirements #1414

Closed
chrisz100 opened this issue Sep 16, 2019 · 4 comments
Closed

local start-api does not install requirements #1414

chrisz100 opened this issue Sep 16, 2019 · 4 comments
Labels
area/build sam build command area/local/start-api sam local start-api command type/ux

Comments

@chrisz100
Copy link

chrisz100 commented Sep 16, 2019

Description

Using local start-api does error me with uninstalled dependencies with python 3.7
When I run sam build and sam local start-api after it works, but it then requires me to always test, stop the api, re-run sam build and restart sam local start-api

Steps to reproduce

  1. initialise a sam project with python 3.7
  2. put any dependency into the requirements.txt
  3. invoke the library in the default function
  4. run sam local start-api
  5. execute the function

Observed result

Code /Users/.../hello_world is not a zip/jar file
Skipping building an image since no layers were defined

Fetching lambci/lambda:python3.7 Docker container image......
Mounting /Users/.../hello_world as /var/task:ro,delegated inside runtime container
Starting a timer for 3 seconds for function 'HelloWorldFunction'
START RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'jwt'
END RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72
REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72	Duration: 2.93 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 22 MB
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Unable to import module 'app': No module named 'jwt'"
}
Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object). Response received:
2019-09-16 22:51:00 127.0.0.1 - - [16/Sep/2019 22:51:00] "GET /hello?foo=bar HTTP/1.1" 502 -

Expected result

I expect it to download the requirements.txt before calling the api.
Alternatively it should respect the code changes whilst this function is running when having to use sam build to install dependencies.

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

  1. OS: macOS
  2. sam --version: SAM CLI, version 0.21.0
@jfuss
Copy link
Contributor

jfuss commented Sep 17, 2019

@chrisz100 Thank you for the report. Currently, sam build is a required step before invoking your function. We are looking to solve some of this pain through a combination of #921 (introducing a --watch option) and #805 (incremental builds). You can create an alias or shell script that runs both commands.

@jfuss jfuss added area/build sam build command area/local/start-api sam local start-api command type/ux labels Sep 17, 2019
@jfuss
Copy link
Contributor

jfuss commented Dec 13, 2019

Closing, as this is currently by design and we have two other issues tracking improvements to the build flow that could unlock building before invoke automatically.

@jfuss jfuss closed this as completed Dec 13, 2019
@iongion
Copy link

iongion commented Jul 29, 2021

sam --version
SAM CLI, version 1.27.2

sam build installs deps properly

2021-07-29 12:27:04,912 | Final compatible: {jmespath==0.10.0(wheel), botocore==1.21.9(wheel), mysql-connector-python==8.0.26(wheel), click==8.0.1(wheel), setuptools==57.4.0(wheel), idna==3.2(wheel), cryptography==3.3.2(wheel), pyjwt==2.1.0(wheel), pip-tools==6.2.0(wheel), wheel==0.36.2(wheel), urllib3==1.26.6(wheel), six==1.16.0(wheel), cffi==1.14.6(wheel), boto3==1.18.4(wheel), requests==2.26.0(wheel), certifi==2021.5.30(wheel), redis==3.5.3(wheel), s3transfer==0.5.0(wheel), jsonschema==3.2.0(wheel), protobuf==3.15.8(wheel), pep517==0.11.0(wheel), pycparser==2.20(wheel), importlib-metadata==4.6.1(wheel), typing-extensions==3.10.0.0(wheel), python-dateutil==2.8.2(wheel), attrs==21.2.0(wheel), pip==21.2.1(wheel), pyrsistent==0.18.0(wheel), zipp==3.5.0(wheel), tomli==1.1.0(wheel), charset-normalizer==2.0.3(wheel)}
2021-07-29 12:27:04,912 | Final incompatible: {protobuf==3.15.8(wheel), pyrsistent==0.18.0(wheel), cryptography==3.3.2(wheel), cffi==1.14.6(wheel)}
2021-07-29 12:27:04,912 | Final missing wheels: set()
2021-07-29 12:27:06,855 | PythonPipBuilder:ResolveDependencies succeeded
2021-07-29 12:27:06,855 | Running PythonPipBuilder:CopySource
2021-07-29 12:27:06,885 | PythonPipBuilder:CopySource succeeded

sam local start-api complains that deps don't exist as soon as I curl the HTTP api locally

2021-07-29 12:30:13,264 | Starting a timer for 180 seconds for function 'MyLambda'
START RequestId: 36ca0527-d4d9-4cd7-a089-38242032b2d3 Version: $LATEST
Unable to import module 'mylambda_handler': No module named 'jsonschema'

@andriiZhabchyk
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command area/local/start-api sam local start-api command type/ux
Projects
None yet
Development

No branches or pull requests

4 participants