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

Bug: FileNotFoundError on "sam build --use-container"

Open loelindstrom opened this issue 1 year ago • 2 comments

Description:

I was following this tutorial: hello-world
And since I don't have the correct python I used sam build --use-container.

Then the application seems to be built, but then an FileNotFoundError: is thrown.

If I try to build again I am only seeing the error nothing else.

However, if I change something in the hello-world/app.py file (adding an exclamation mark to the returned string) then the error disappears and everything seems to be working as it should. So probably not any major bug.

Steps to reproduce:

sam init
1
1
y
[enter]
[enter]
[enter]
[enter]

cd sam-app
sam build --use-container --debug

Observed result:

Click to see output
2024-02-29 14:57:02,095 | Config file location: /mnt/c/Users/XXX/sam-app/samconfig.toml 

2024-02-29 14:57:02,100 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at 

'/mnt/c/Users/XXX/sam-app/samconfig.toml'... 

2024-02-29 14:57:02,103 | Configuration values successfully loaded. 

2024-02-29 14:57:02,104 | Configuration values are: {'stack_name': 'sam-app', 'cached': True, 'parallel': True} 

2024-02-29 14:57:02,120 | Using SAM Template at /mnt/c/Users/XXX/sam-app/template.yaml 

2024-02-29 14:57:02,173 | Using config file: samconfig.toml, config environment: default 

2024-02-29 14:57:02,175 | Expand command line arguments to: 

2024-02-29 14:57:02,176 | --template_file=/mnt/c/Users/XXX/sam-app/template.yaml --use_container --parallel --mount_with=READ 

--build_dir=.aws-sam/build --cache_dir=.aws-sam/cache --cached 

2024-02-29 14:57:02,211 | 'build' command is called 

2024-02-29 14:57:02,212 | Starting Build use cache 

2024-02-29 14:57:02,212 | Starting Build inside a container 

2024-02-29 14:57:02,225 | No Parameters detected in the template 

2024-02-29 14:57:02,283 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id 

2024-02-29 14:57:02,283 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id 

2024-02-29 14:57:02,285 | 0 stacks found in the template 

2024-02-29 14:57:02,286 | No Parameters detected in the template 

2024-02-29 14:57:02,305 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id 

2024-02-29 14:57:02,306 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id 

2024-02-29 14:57:02,309 | 2 resources found in the stack 

2024-02-29 14:57:02,310 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/' 

2024-02-29 14:57:02,311 | --base-dir is not presented, adjusting uri hello_world/ relative to /mnt/c/Users/XXX/sam-app/template.yaml 

2024-02-29 14:57:02,375 | 2 resources found in the stack 

2024-02-29 14:57:02,376 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/' 

2024-02-29 14:57:02,388 | Instantiating build definitions 

2024-02-29 14:57:02,391 | No previous build graph found, generating new one 

2024-02-29 14:57:02,393 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(python3.9, 

/mnt/c/Users/XXX/sam-app/hello_world, Zip, , e3f59988-10b4-45b4-8036-621ab7e04461, {}, {}, x86_64, []), Function: 

Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='python3.9', memory=128, timeout=3, 

handler='app.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/mnt/c/Users/XXX/sam-app/hello_world', environment=None, 

rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, 

metadata={'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None, 

function_build_info=<FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which can be build with SAM CLI')>, stack_path='', 

runtime_management_config=None, logging_config=None)) 

2024-02-29 14:57:02,417 | Async execution started 

2024-02-29 14:57:02,418 | Invoking function functools.partial(<bound method ParallelBuildStrategy.build_single_function_definition of 

<samcli.lib.build.build_strategy.ParallelBuildStrategy object at 0x7f38471104d0>>, <samcli.lib.build.build_graph.FunctionBuildDefinition object at 0x7f3846fa4250>) 

2024-02-29 14:57:02,420 | Running incremental build for runtime python3.9 for following resources (HelloWorldFunction) 

2024-02-29 14:57:02,421 | Waiting for async results 

2024-02-29 14:57:02,465 | Cache is invalid, running build and copying resources for following functions (HelloWorldFunction) 

2024-02-29 14:57:02,466 | Building codeuri: /mnt/c/Users/XXX/sam-app/hello_world runtime: python3.9 metadata: {} architecture: x86_64 functions: 

HelloWorldFunction 

2024-02-29 14:57:02,468 | Building to following folder /mnt/c/Users/XXX/sam-app/.aws-sam/build/HelloWorldFunction 

2024-02-29 14:57:02,509 | Checking free port on 127.0.0.1:7248 

  

Fetching public.ecr.aws/sam/build-python3.9:latest-x86_64 Docker container image...... 

2024-02-29 14:57:04,550 | Mounting /mnt/c/Users/XXX/sam-app/hello_world 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 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)' 

Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', 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 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)' 

Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)' 

Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)' 

Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)' 

Registering workflow 'RustCargoLambdaBuilder' with capability 'Capability(language='rust', dependency_manager='cargo', application_framework=None)' 

Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)' 

Running workflow 'PythonPipBuilder' 

Running PythonPipBuilder:ResolveDependencies 

calling pip download -r /tmp/samcli/source/requirements.txt --dest /tmp/samcli/scratch --exists-action i 

pip stdout: b'Collecting requests\n  Downloading requests-2.31.0-py3-none-any.whl (62 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 62.6/62.6 kB 4.4 MB/s eta 0:00:00\nCollecting certifi>=2017.4.17\n  Downloading certifi-2024.2.2-py3-none-any.whl (163 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 163.8/163.8 kB 6.0 MB/s eta 0:00:00\nCollecting urllib3<3,>=1.21.1\n  Downloading urllib3-2.2.1-py3-none-any.whl (121 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 121.1/121.1 kB 8.4 MB/s eta 0:00:00\nCollecting charset-normalizer<4,>=2\n  Downloading charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 142.3/142.3 kB 8.0 MB/s eta 0:00:00\nCollecting idna<4,>=2.5\n  Downloading idna-3.6-py3-none-any.whl (61 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 61.6/61.6 kB 5.8 MB/s eta 0:00:00\nSaved /tmp/samcli/scratch/requests-2.31.0-py3-none-any.whl\nSaved /tmp/samcli/scratch/certifi-2024.2.2-py3-none-any.whl\nSaved /tmp/samcli/scratch/charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\nSaved /tmp/samcli/scratch/idna-3.6-py3-none-any.whl\nSaved /tmp/samcli/scratch/urllib3-2.2.1-py3-none-any.whl\nSuccessfully downloaded requests certifi charset-normalizer idna urllib3\n' 

pip stderr: b"WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.\nPlease see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.\nTo avoid this problem you can invoke Python with '-m pip' instead of running pip directly.\n\n[notice] A new release of pip is available: 23.0.1 -> 24.0\n[notice] To update, run: pip install --upgrade pip\n" 

Full dependency closure: {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

initial compatible: {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

initial incompatible: set() 

Downloading missing wheels: set() 

compatible wheels after second download pass: {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

Build missing wheels from sdists (C compiling True): set() 

compatible after building wheels (no C compiling): {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

Build missing wheels from sdists (C compiling False): set() 

compatible after building wheels (C compiling): {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

Final compatible: {charset-normalizer==3.3.2(wheel), requests==2.31.0(wheel), urllib3==2.2.1(wheel), idna==3.6(wheel), certifi==2024.2.2(wheel)} 

Final incompatible: set() 

Final missing wheels: set() 

PythonPipBuilder:ResolveDependencies succeeded 

Running PythonPipBuilder:CopySource 

Copying source file (/tmp/samcli/source/app.py) to destination (/tmp/samcli/artifacts/app.py) 

Copying source file (/tmp/samcli/source/requirements.txt) to destination (/tmp/samcli/artifacts/requirements.txt) 

Copying source file (/tmp/samcli/source/__init__.py) to destination (/tmp/samcli/artifacts/__init__.py) 

PythonPipBuilder:CopySource succeeded 

2024-02-29 14:57:07,059 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "result": {"artifacts_dir": "/tmp/samcli/artifacts"}} 

2024-02-29 14:57:07,060 | Build inside container was successful. Copying artifacts from container to host 

2024-02-29 14:57:08,130 | Copying from container: /tmp/samcli/artifacts/. -> /mnt/c/Users/XXX/sam-app/.aws-sam/build/HelloWorldFunction 

2024-02-29 14:57:10,034 | Build inside container succeeded 

2024-02-29 14:57:14,929 | Async execution completed 

2024-02-29 14:57:14,945 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id 

2024-02-29 14:57:14,953 | 2 resources found in the stack 

2024-02-29 14:57:14,954 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/' 

  

Build Succeeded 

2024-02-29 14:57:15,017 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 

Traceback (most recent call last): 

  File "samcli/__main__.py", line 12, in <module> 

  File "click/core.py", line 1157, in __call__ 

  File "click/core.py", line 1078, in main 

  File "click/core.py", line 1688, in invoke 

  File "click/core.py", line 1434, in invoke 

  File "click/core.py", line 783, in invoke 

  File "samcli/cli/cli_config_file.py", line 347, in wrapper 

  File "click/decorators.py", line 92, in new_func 

  File "click/core.py", line 783, in invoke 

  File "samcli/lib/telemetry/metric.py", line 180, in wrapped 

  File "samcli/lib/telemetry/metric.py", line 215, in _send_command_run_metrics 

  File "samcli/lib/telemetry/metric.py", line 253, in _get_project_details 

  File "samcli/lib/iac/cdk/utils.py", line 27, in is_cdk_project 

  File "samcli/lib/iac/cdk/utils.py", line 73, in _relevant_cdk_files_are_present 

FileNotFoundError: [Errno 2] No such file or directory 

[5614] Failed to execute script '__main__' due to unhandled exception! 

Expected result:

That no error would be thrown.

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

  1. OS: WSL (Ubuntu 22.04.3 distro) on Windows 10
  2. sam --version: SAM CLI, version 1.110.0
  3. AWS region: eu-north-1
Click to see output from `docker info`
Client:
 Version:    25.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.3-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.22
    Path:     /usr/local/lib/docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.21
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /usr/local/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.3.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 4
  Running: 0
  Paused: 0
  Stopped: 4
 Images: 10
 Server Version: 25.0.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.605GiB
 Name: docker-desktop
 ID: 70719ed3-4bf9-47ca-8a72-2c1ce05d3a33
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Click to see output of `sam --info`
# Paste the output of `sam --info` here
{
  "version": "1.110.0",
  "system": {
    "python": "3.11.3",
    "os": "Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35"
  },
  "additional_dependencies": {
    "docker_engine": "25.0.2",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

loelindstrom avatar Feb 29 '24 14:02 loelindstrom

Hi, thanks for bringing up the issue, looking closer it seems like this is closely related to this issue, which is a bug occurring from WSL when using newly created automounted directories, which explain why editing your file fixes the issue. Regardless however, while we may not be able to fix this issue since it comes from WSL, we should not be panicking like this especially since this error is occurring in the telemetry and not in the actual build which succeeded. Marking this as a bug and letting the team know. Thanks

jysheng123 avatar Feb 29 '24 23:02 jysheng123

@jysheng123
Ok thanks for the response! I'm sorry if it sounded like panicking or if I reported it wrongly.

It's my first time reporting something, so let me know if it is anything I can improve.

loelindstrom avatar Mar 01 '24 07:03 loelindstrom

Patch is released in v1.121.0. Closing

github-actions[bot] avatar Jul 30 '24 17:07 github-actions[bot]