简体   繁体   English

无法找到模块 - 带有 HelloWorld 示例的 AWS Sam CLI 本地调用(Windows / Rancher 桌面)

[英]Unable to find module - AWS Sam CLI Local Invoke with HelloWorld Example (Windows / Rancher Desktop)

With the recent subscription changes to Docker desktop, I am attempting to run SAM CLI on windows using Rancher desktop as an alternative.随着最近对 Docker 桌面的订阅更改,我正在尝试使用 Rancher 桌面作为替代方案在 windows 上运行 SAM CLI。

While AWS SAM does not officially support Rancher, I have colleagues who have successfully done this.虽然 AWS SAM 没有正式支持 Rancher,但我有同事已经成功地做到了这一点。 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:我验证了一个简单的“echo hello world”docker 图像在 powershell 中运行,但是一旦我使用 SAM cli,我就会收到以下错误:

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.我认为找不到“function1”模块是一个红鲱鱼。 I know this function exists in the main code.我知道这个 function 存在于主代码中。 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解决尝试

Runtimes/Versions:运行时/版本:

  • Using rancher 1.5.0 on Windows 11在 Windows 11 上使用牧场主 1.5.0
  • Using sam cli 1.53.0使用山姆 cli 1.53.0
  • Docker version 20.10.17-rd, build c2e4e01 Docker 版本 20.10.17-rd,构建 c2e4e01
  • python 3.9 python 3.9

This is an open issue .这是一个悬而未决的问题

A workaround is to use Docker Desktop 4.11.1一种解决方法是使用Docker Desktop 4.11.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM