[Small story] What to do if "Error with child process: Building resource'awsToolkitSamLocalResource'" does not work when Lambda is locally executed by SAM from VS Code

wrap up

If the version of pip inside SAM and the version of local pip do not match, it may not work, so you need to modify the version of local pip.

Execution environment

item name version
OS MacOS High Sierra 10.13.6
VSCode 1.40.2
SAM 0.37.0
Python 3.7.3
pip 19.3.1(19 in the article.2.Change to 3)

problem

It may not work when you want to test in a local environment using the AWS Toolkit from VS Code's "Run Locally". For example, the following error.


Local invoke of SAM Application has ended.
Preparing to run app.lambda_handler locally...
Building SAM Application...
An error occurred trying to run SAM Application locally: Error with child process: Building resource 'awsToolkitSamLocalResource'
,Running PythonPipBuilder:ResolveDependencies
,Error: PythonPipBuilder:ResolveDependencies - Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'module' object is not callable

Cause (probably)

It seems that the issue that occurred in SAM has not been solved yet in VS Code's AWS Toolkit. GitHub : sam build fails for python3.7 functions with pip==19.3 installed If you try the same settings and execute the following command from the terminal, there is no problem even if the verison of SAM and pip are the same.

$ sam local invoke HelloWorldFunction --event events/event.json

Coping

Although it is a temporary measure, if you modify the version of pip to the following, it will be possible to execute normally even from VS Code.

$ pip install pip==19.2.3

Log "Run Locally" from VS Code after changing pip version

Fetching lambci/lambda:python3.7 Docker container image......
Mounting /tmp/aws-toolkit-vscode/vsctkytL1AY/output/awsToolkitSamLocalResource as /var/task:ro,delegated inside runtime container

...(Omission)...

{"statusCode":200,"body":"{\"message\": \"hello worldXXX\"}"}

Recommended Posts

[Small story] What to do if "Error with child process: Building resource'awsToolkitSamLocalResource'" does not work when Lambda is locally executed by SAM from VS Code
What to do if pyenv install does not proceed with an error
What to do if an error occurs when loading a python project created with poetry into VS Code
What to do if Python IntelliSense is not displayed in VS Code on Windows
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do if an error occurs when importing numpy with VScode
Notes on what to do when matplotlib scatter () / scatter3d () does not work
Example of what to do when the sample script does not work (OpenCV-Python)
A story that sometimes does not work if pip is up to date
What to do if you get an error when installing python with pyenv
[EC2] What to do when selenium is stuck and processing does not proceed
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do when python3 type venv does not work well on Raspberry Pi
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if Python does not switch from the System version in pyenv
What to do if sys / cdefs.h does not exist
What to do if pyenv is not enabled (zsh)
What to do if you get an Undefined error when trying to use pip with pyenv
What to do when Japanese is not displayed on matplotlib
What to do when an error occurs with import _ssl
[Beginner] What to do when "[Errno 2] File b'test.csv' does not exist: b'test.csv" is displayed when reading pandas csv
What to do if the user name is changed and the pyenv library path does not pass