aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: sam build problem in Rancher Desktop

Open EdeBont opened this issue 4 years ago • 14 comments

Description:

I am trying to build an AWS python lambda function in a container for debugging. When executing sam build --use-container an error is generated because dependencies are not build. This is because it says it cannot find the requirements.txt file. The requirements.txt file is present. The complete setup worked without any change under Docker Desktop, so it looks like it is Rancher related.

Steps to reproduce:

Install rancher desktop. Container runtime is set to dockerd (moby) Exposed Rancher Desktop Kubernetes configuration an docker socket to WSL is set to Ubuntu-20.04 Kubernetes version is set to 1.24.3

Observed result:

PS C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app> sam build --use-container --debug 2022-08-18 14:43:37,696 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2022-08-18 14:43:37,696 | Using config file: samconfig.toml, config environment: default 2022-08-18 14:43:37,697 | Expand command line arguments to: 2022-08-18 14:43:37,697 | --template_file=C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml --use_container --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache 2022-08-18 14:43:38,716 | 'build' command is called 2022-08-18 14:43:38,716 | Starting Build inside a container 2022-08-18 14:43:38,719 | No Parameters detected in the template 2022-08-18 14:43:38,734 | There is no customer defined id or cdk path defined for resource ProcessMail2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,734 | There is no customer defined id or cdk path defined for resource KadasterMetingParse2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,735 | 0 stacks found in the template 2022-08-18 14:43:38,735 | No Parameters detected in the template 2022-08-18 14:43:38,743 | There is no customer defined id or cdk path defined for resource ProcessMail2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,744 | There is no customer defined id or cdk path defined for resource KadasterMetingParse2021, so we will use the resource logical id as the resource id 2022-08-18 14:43:38,744 | 2 resources found in the stack 2022-08-18 14:43:38,744 | Found Serverless function with name='ProcessMail2021' and CodeUri='ProcessMail2021/' 2022-08-18 14:43:38,745 | --base-dir is not presented, adjusting uri ProcessMail2021/ relative to C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml 2022-08-18 14:43:38,745 | Found Serverless function with name='KadasterMetingParse2021' and CodeUri='KadasterMetingParse2021/' 2022-08-18 14:43:38,745 | --base-dir is not presented, adjusting uri KadasterMetingParse2021/ relative to C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\template.yaml 2022-08-18 14:43:38,749 | Instantiating build definitions 2022-08-18 14:43:38,752 | Same function build definition found, adding function (Previous: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021, Zip, , 22fa8c0f-c842-4add-b22b-b61dd32be94c, {}, {}, x86_64, []), Current: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021, Zip, , 8cbbde39-4ccc-435d-894f-5f8b6b4f9c16, {}, {}, x86_64, []), Function: Function(function_id='ProcessMail2021', name='ProcessMail2021', functionname='ProcessMail2021', runtime='python3.8', memory=None, timeout=3, handler='ProcessMail.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021', environment=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'ProcessMail2021'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='')) 2022-08-18 14:43:38,753 | Same function build definition found, adding function (Previous: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021, Zip, , cf40a036-b307-460c-bc2d-55033f694430, {}, {}, x86_64, []), Current: BuildDefinition(python3.8, C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021, Zip, , 289c9d91-2cfe-4189-a0ba-08a2ffc51318, {}, {}, x86_64, []), Function: Function(function_id='KadasterMetingParse2021', name='KadasterMetingParse2021', functionname='KadasterMetingParse2021', runtime='python3.8', memory=None, timeout=3, handler='Kadaster_MetingParse.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021', environment=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'KadasterMetingParse2021'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='')) 2022-08-18 14:43:38,754 | Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: ProcessMail2021 2022-08-18 14:43:38,756 | Building to following folder C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app.aws-sam\build\ProcessMail2021

Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image...... 2022-08-18 14:43:40,230 | Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 as /tmp/samcli/source:ro,delegated inside runtime container Using the request object from command line argument Loading workflow module 'aws_lambda_builders.workflows' Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)' Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)' Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)' Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)' Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)' Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)' Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)' Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)' Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)' Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)' requirements.txt file not found. Continuing the build without dependencies. Running workflow 'PythonPipBuilder' Running PythonPipBuilder:CopySource Creating target folders at /tmp/samcli/artifacts Copying directory metadata from source (/tmp/samcli/source) to destination (/tmp/samcli/artifacts) PythonPipBuilder:CopySource succeeded 2022-08-18 14:43:40,829 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '33afc1f0-1091-47c2-b3ce-971cc2d2d4b7', 'installationId': '73f2b68e-1de6-4d57-9b90-0cb69a0ecdf3', 'sessionId': 'c1e8073f-1048-48b1-a264-de2d2c24486c', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.55.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 3131, 'exitReason': 'error', 'exitCode': 255}}]} 2022-08-18 14:43:41,460 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Traceback (most recent call last): File "runpy.py", line 194, in _run_module_as_main File "runpy.py", line 87, in run_code File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli_main.py", line 12, in cli(prog_name="sam") File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in call return self.main(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main rv = self.invoke(ctx) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 166, in wrapped raise exception # pylint: disable=raising-bad-type File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 124, in wrapped return_value = func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\version_checker.py", line 41, in wrapped actual_result = func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\cli\main.py", line 87, in wrapper return func(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 182, in cli do_cli( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 262, in do_cli ctx.run() File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\build_context.py", line 251, in run build_result = builder.build() File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 221, in build return ApplicationBuildResult(build_graph, build_strategy.build()) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_strategy.py", line 80, in build result.update(self._build_functions(self._build_graph)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_strategy.py", line 90, in _build_functions function_build_results.update(self.build_single_function_definition(build_definition)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\build_strategy.py", line 163, in build_single_function_definition result = self._build_function( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 645, in _build_function return self._build_function_on_container( File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 831, in _build_function_on_container container.wait_for_logs(stdout=stdout_stream, stderr=stderr_stream) 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: File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\types\daemon.py", line 32, in next return next(self._stream) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 406, in gen = (demux_adaptor(*frame) for frame in gen) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 94, in frames_iter_no_tty (stream, n) = next_frame_header(socket) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 66, in next_frame_header data = read_exactly(socket, 8) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 51, in read_exactly next_data = read(socket, n - len(data)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 35, in read return socket.recv(n) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 23, in wrapped return f(self, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 117, in recv err, data = win32file.ReadFile(self._handle, bufsize) pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')

Expected result:

A build lambda ready for debugging

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

  1. OS: Windows 10 Enterprise edition
  2. sam --version: SAM CLI, version 1.55.0
  3. AWS region: eu-central-1

Add --debug flag to command you are running

EdeBont avatar Aug 18 '22 12:08 EdeBont

@EdeBont Maybe multiple things are happening here. I will start off by saying, I am not familiar with Rancher Desktop but will be speaking in Docker terms.

So if your function does have a requirements.txt file in it's CodeUri directory, then this could be a mounting issue of the CodeUri into the container. With Docker, I know there are setting to enable what directories can be mounted. Is there something similar with Rancher Desktop that might be failing? Docker hides this and basically acts as if the mount was successful, so not sure if Rancher does the same thing.

The stacktrace seems to suggest we can't read the file from the container. So before we get to that, I want to make sure things are getting into the container correctly.

jfuss avatar Aug 19 '22 16:08 jfuss

@jfuss According to Rancher documentation mount settings are as following: "Q: Does file sharing work similarly to Docker Desktop? Do I have to do any additional configuration to mount volumes to VMs? A: Currently, the following directories are shared by default: /Users/$USER on macOS, /home/$USER on Linux, and /tmp/rancher-desktop on both. For Windows, all files are automatically shared via WSL2."

EdeBont avatar Aug 22 '22 06:08 EdeBont

@EdeBont Does this only happen in Rancher? What about Docker?

jfuss avatar Aug 29 '22 17:08 jfuss

@EdeBont Does this only happen in Rancher? What about Docker?

@jfuss As I mentioned in my initial post we had no problem when we using Docker Desktop. So at this moment this problem only exists when using Rancher Desktop.

EdeBont avatar Aug 30 '22 08:08 EdeBont

@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.

Does this happen all the time?

Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.

jfuss avatar Aug 30 '22 15:08 jfuss

@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.

Does this happen all the time?

Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.

Hi @jfuss , No need to apologize!!

Yes it happens all the time, also in other projects which used to work ok using Docker Desktop.

The project setup is simple: root (containing template.yaml) |project folder | init.py |_____ process.py |_____ requirements.txt (containing ptvsd, requests, psycopg2-binary, boto3)

As mentioned this setup works without any problem when using Docker Desktop. As soon as I switch to Rancher Desktop there is a problem.

And it looks like I am not the only one running into this problem: https://github.com/aws/aws-sam-cli/issues/3595#issuecomment-1217674852

EdeBont avatar Aug 31 '22 06:08 EdeBont

@EdeBont Sorry I am been jumping between issues and was brought up to check from the team.

Does this happen all the time?

Can you provide an example project or tell me how your project is setup? Trying to see maybe if there are other issues going on that is just masked by the failure.

same with me.

Running PythonPipBuilder:ResolveDependencies Running PythonPipBuilder:CopySource Traceback (most recent call last): File "runpy.py", line 194, in _run_module_as_main File "runpy.py", line 87, in run_code File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli_main.py", line 12, in cli(prog_name="sam") File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in call return self.main(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main rv = self.invoke(ctx) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke return callback(*args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 176, in wrapped raise exception # pylint: disable=raising-bad-type File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 94, in frames_iter_no_tty (stream, n) = next_frame_header(socket) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 66, in next_frame_header data = read_exactly(socket, 8) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 51, in read_exactly next_data = read(socket, n - len(data)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 35, in read return socket.recv(n) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 23, in wrapped return f(self, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 117, in recv err, data = win32file.ReadFile(self._handle, bufsize) pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')

Environment details

Docker version 20.10.17, build 100c701 SAM CLI, version 1.57.0 OS: Windows 11

jgverzosa avatar Sep 21 '22 04:09 jgverzosa

I got it working again using the nightly build of SAM:

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html#serverless-sam-cli-install-windows-nightly-build

AndyPrince avatar Sep 22 '22 09:09 AndyPrince

I got it working again using the nightly build of SAM:

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html#serverless-sam-cli-install-windows-nightly-build

That actually solved my problem to at first glance, at second not!! Though it still says "requirements.txt file not found"

PS C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app> sam-nightly build --use-container
Starting Build inside a container
Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: ProcessMail2021

Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\ProcessMail2021 as /tmp/samcli/source:ro,delegated inside runtime container
requirements.txt file not found. Continuing the build without dependencies.
Running PythonPipBuilder:CopySource
Building codeuri: C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021 runtime: python3.8 metadata: {} architecture: x86_64 functions: KadasterMetingParse2021

Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
Mounting C:\Repositories\fgs-asset-information\Kadaster\kadaster-sam-app\KadasterMetingParse2021 as /tmp/samcli/source:ro,delegated inside runtime container

Build Succeeded

Built Artifacts  : .aws-sam\build
Built Template   : .aws-sam\build\template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
[*] Deploy: sam deploy --guided


SAM CLI update available (1.57.0); (1.57.0.dev202209200902 installed)
To download: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
requirements.txt file not found. Continuing the build without dependencies.
Running PythonPipBuilder:CopySource

Almost but no sigar. After some more testing it is still not working, not able to debug anything.

EdeBont avatar Sep 22 '22 12:09 EdeBont

getting the same issue with the hello world app. requirements.txt is not found. I'm on Windows 11, using Rancher Desktop 1.62 and sam cli 1.66.0. if you need additional logs/details to troubleshoot, I'm happy to provide

romaindup avatar Dec 02 '22 03:12 romaindup

Hi folks, sorry I just saw this. I tried with a sam init template for python on MacOS and it didn't have any issues. It seems this might be a problem on Rancher Desktop's side, specifically on Windows. I found this issue on Rancher's github which might be the problem: https://github.com/rancher-sandbox/rancher-desktop/issues/3014

SAM CLI does mount a temporary directory onto the container, so that we can perform the building in there. It seems like Rancher Desktop on Windows is potentially not creating this directory or not mounting it properly.

Docker Desktop does automatically create these directories: https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only

When the host directory of a bind-mounted volume doesn’t exist, Docker will automatically create this directory on the host for you.

torresxb1 avatar Dec 07 '22 20:12 torresxb1

Thanks for investigating. Is there a way for sam to create the folder before starting the container? wondering if that would solve the problem

romaindup avatar Dec 08 '22 07:12 romaindup

I am not sure if creating this folder by SAM CLI is a good solution or not, as the problem is related to Rancher and not SAM CLI. I will share this issue with the team and discuss this as a feature request.

moelasmar avatar May 23 '23 23:05 moelasmar

Same issue :(

aleivajandro avatar Jun 18 '23 14:06 aleivajandro