With the recent subscription changes to Docker desktop, I am attempting to run SAM CLI on windows using Rancher desktop as an alternative.
While AWS SAM does not officially support Rancher, I have colleagues who have successfully done this. I verified a simple "echo hello world" docker image runs in powershell, but as soon as I use SAM cli I get the following error:
PS C:\Users\localadmin\Documents\Documents\GitHub\cdk-test\sam-app-master> sam local invoke --debug
2022-08-11 15:18:41,481 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-08-11 15:18:41,482 | Using config file: samconfig.toml, config environment: default
...
2022-08-11 15:18:41,484 | local invoke command is called
..
2022-08-11 15:18:41,608 | Found Serverless function with name='TestFunction' and CodeUri='TestFunction'
2022-08-11 15:18:41,635 | Invoking function1.lambda_handler (python3.9)
..
2022-08-11 15:18:41,671 | Resolving code path. Cwd=C:\Users\localadmin\Documents\project-folder\.aws-sam\build, CodeUri=C:\Users\localadmin\Documents\project-folder\.aws-sam\build\TestFunction
..
2022-08-11 15:18:41,716 | Skip pulling image and use local one: public.ecr.aws/sam/emulation-python3.9:rapid-1.53.0-x86_64.
2022-08-11 15:18:41,717 | Mounting C:\Users\localadmin\Documents\project-folder\.aws-sam\build\TestFunction as /var/task:ro,delegated inside runtime container
2022-08-11 15:18:42,730 | Starting a timer for 3 seconds for function 'TestFunction'
START RequestId: 91d0a4d2-d7f6-4ec1-a064-4b1c50a50ba1 Version: $LATEST
Traceback (most recent call last): Unable to import module 'function1': No module named 'function1'
END RequestId: 91d0a4d2-d7f6-4ec1-a064-4b1c50a50ba1**
REPORT RequestId: 91d0a4d2-d7f6-4ec1-a064-4b1c50a50ba1 Init Duration: 0.27 ms Duration: 190.42 ms Billed Duration: 191 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorMessage": "Unable to import module 'function1': No module named 'function1'", "errorType": "Runtime.ImportModuleError", "requestId": "91d0a4d2-d7f6-4ec1-a064-4b1c50a50ba1", "stackTrace": []}Exception in thread Thread-2:
Traceback (most recent call last):
File "threading.py", line 932, in _bootstrap_inner
File "threading.py", line 870, in run
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\container.py", line 335, in wait_for_logs
self._write_container_output(logs_itr, stdout=stdout, stderr=stderr)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\container.py", line 400, in _write_container_output
for stdout_data, stderr_data in output_itr:
...
pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
I think the cannot find "function1" module is a red herring. I know this function exists in the main code. I think the mounting is successful (bolded in the debug log above).
I believe it must be a file-sharing issue but I have not found anything online that explains how to give rancher access to the host code if that is the case.
Resolution Attempts
- Starting from the most basic SAM example (https://github.com/amazon-archives/serverless-app-examples/tree/master/python/hello-world-python3)
- Attempting solutions recommended on this issue and this issue
Runtimes/Versions:
- Using rancher 1.5.0 on Windows 11
- Using sam cli 1.53.0
- Docker version 20.10.17-rd, build c2e4e01
- python 3.9