Open chkothe opened 5 years ago
Was able to replicate
Outside of SAM command:
/Users/alfredbr/IdeaProjects/SamMaven/venv/bin/python /Users/alfredbr/aws-intellij-toolkit/jetbrains-core/build/idea-sandbox/plugins/python-ce/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 50466 --file /Users/alfredbr/IdeaProjects/PythonSam/hello_world/app.py
Inside of SAM command:
/var/lang/bin/python3.7 -u /tmp/lambci_debug_files/pydevd.py --DEBUG --multiprocess --port. 51971 --file /var/runtime/bootstrap
Using the lambda image as a remote python interpreter results in:
python -u /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --port 53737 --file /opt/project/hello_world/app.py
Which maps with what we do in SAM and it does work.
So I have a work around, but I do not know why pydevd is requiring it.
Add
Environment:
Variables:
PYTHONPATH: '/var/task'
to your template.yaml.
I don't see a way I can fix this in the toolkit, since the toolkit can only add environment variables if already defined in your template.
Ok good to know!
Okay, I see. Pydev adds the directory of argument to --file
into sys path using sys.path(0, ...)
, but that is /var/runtime, not /var/task. (https://github.com/fabioz/PyDev.Debugger/blob/fff160b1327e248eb847f5adc70113f1fb60b8e5/pydevd.py#L1770)
I tried to put pydevd into module module, but that just led to failing to start.
('Bound to port ', '61540')
('Connection accepted',)
debugger: received >>501 1 0.1 UNIX
<<
Received command: CMD_VERSION 501 1 0.1 UNIX
sending cmd --> CMD_VERSION 501 1 @@BUILD_NUMBER@@
Connected to pydev debugger (build 191.6183.87)
debugger: received >>501 3 0.1 UNIX
<<
Received command: CMD_VERSION 501 3 0.1 UNIX
sending cmd --> CMD_VERSION 501 3 @@BUILD_NUMBER@@
debugger: received >>111 5 python-line /var/task/app.py 38 lambda_handler THREAD None None
<<
Received command: CMD_SET_BREAK 111 5 python-line /var/task/app.py 38 lambda_handler THREAD None None
Added breakpoint:/var/task/app.py - line:38 - func_name:b'lambda_handler'
debugger: received >>122 7 python-BaseException None None 0 1 0
146 9 SHOW_RETURN_VALUES 0
101 11
<<
Received command: CMD_ADD_EXCEPTION_BREAK 122 7 python-BaseException None None 0 1 0
Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f4001e166d8>}
Received command: CMD_SHOW_RETURN_VALUES 146 9 SHOW_RETURN_VALUES 0
Show return values: False
Received command: CMD_RUN 101 11
No module named /var/runtime/bootstrap
Describe the bug Some packages use pkg_resource.get_distribution() at runtime (e.g., to find their own version) and for some packages this seems to fail in Debug mode, while it succeeds in Run mode (e.g., jsonschema==3.0.1).
To reproduce
Fetching lambci/lambda:python3.7 Docker container image...... 2019-06-26 16:10:19 Mounting C:\Users\chris\AppData\Local\Temp\lambdaBuild2884\HelloWorldFunction as /var/task:ro,delegated inside runtime container Connected to pydev debugger (build 191.7479.30) Â Â Â Â raise DistributionNotFound(req, requirers) START RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATEST END RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Init Duration: 1309.12 ms Duration: 0.00 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 34 MB
{ "errorType": "DistributionNotFound", "errorMessage": "The 'jsonschema' distribution was not found and is required by the application", "stackTrace": [ " File \"/var/lang/lib/python3.7/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\n", " File \"/var/lang/lib/python3.7/imp.py\", line 171, in load_source\n module = _load(spec)\n", " File \"\u003cfrozen importlib._bootstrap\u003e\", line 696, in _load\n", " File \"\u003cfrozen importlib._bootstrap\u003e\", line 677, in _load_unlocked\n", " File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 728, in exec_module\n", " File \"\u003cfrozen importlib._bootstrap\u003e\", line 219, in _call_with_frames_removed\n", " File \"/var/task/app.py\", line 3, in \u003cmodule\u003e\n import jsonschema\n", " File \"/var/task/jsonschema/init.py\", line 33, in \u003cmodule\u003e\n version = get_distribution(name).version\n", " File \"/var/lang/lib/python3.7/site-packages/pkg_resources/init.py\", line 481, in get_distribution\n dist = get_provider(dist)\n", " File \"/var/lang/lib/python3.7/site-packages/pkg_resources/init.py\", line 357, in get_provider\n return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]\n", " File \"/var/lang/lib/python3.7/site-packages/pkg_resources/init.py\", line 900, in require\n needed = self.resolve(parse_requirements(requirements))\n", " File \"/var/lang/lib/python3.7/site-packages/pkg_resources/init.py\", line 786, in resolve\n raise DistributionNotFound(req, requirers)\n" ] }
"C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd" build --template C:\DEVEL\SAM\test4\template.yaml --build-dir C:\Users\chris\AppData\Local\Temp\lambdaBuild49 2019-06-26 16:20:32 Building resource 'HelloWorldFunction' 2019-06-26 16:20:32 Running PythonPipBuilder:ResolveDependencies Error: PythonPipBuilder:ResolveDependencies - list index out of range