Skip to content

Bug: PythonUvBuilder:CopyDependencies fails when sam build --cached deletes .aws-sam/build/<FunctionName> #864

Closed

Description

@tomaDev

Description

PythonUvBuilder:CopyDependencies fails with [Errno 2] No such file or directory: '.aws-sam/build/<FunctionName>' when invoked from sam build --cached --beta-features. The cached-build path removes the build output directory but CopyDependencies expects it to already exist.

Destructive failure mode: the failed invocation also wipes .aws-sam/build/ for all functions, so users must sam build --beta-features from scratch to recover.

Filed here per @vicheey's diagnosis on aws/aws-sam-cli#8838 that the fix likely belongs in aws-lambda-builders.

Steps to reproduce

# Any SAM project with 2+ Python functions using python-uv builder
sam build --beta-features          # succeeds
sam build --cached --beta-features # fails — also wipes prior .aws-sam/build/

Observed result

Starting Build use cache
Building codeuri: /path/to/src/my_function runtime: python3.14 architecture: arm64 functions: MyFunction
Auto-detected manifest file: /path/to/src/my_function/pyproject.toml
 Running PythonUvBuilder:CleanUp
 Running PythonUvBuilder:ResolveDependencies
Building Python dependencies using UV
Found uv.lock alongside pyproject.toml - using lock-based build for precise dependencies
Building from UV lock file
 Running PythonUvBuilder:CopyDependencies

Build Failed
Error: PythonUvBuilder:CopyDependencies - [Errno 2] No such file or directory: '/path/to/.aws-sam/build/MyFunction'

.aws-sam/build.toml: every function entry has manifest_hash = "", so cache-decision logic routes through CopyDependencies against a non-existent target dir.

Expected result

sam build --cached --beta-features reuses cached deps when manifest unchanged; only re-copies source. Build dir recreated before CopyDependencies runs. No destructive state-loss on failure.

Notes

  • sam build --beta-features (no --cached): works
  • sam build --parallel --beta-features (no --cached): works
  • sam build --cached --parallel --beta-features: same failure

Environment

Reproduced 2026-04-26:

SAM CLI: 1.158.0
aws-lambda-builders: shipped with sam-cli 1.158.0
Python: 3.14
uv: 0.11.7
OS: macOS 26.3 (aarch64-apple-darwin)

Related: aws/aws-sam-cli#8838

Activity

  1. tomaDev commented on May 13, 2026

    @tomaDev
    ContributorAuthor

    Opened #870 with a fix: CopyDependenciesAction had its source/destination swapped, and UvRunner.install_requirements passed a relative --target through to uv (which runs with cwd=project_dir, so deps landed under the source dir). PR fixes both, with regression coverage in test_workflow.py, test_packager.py, and the existing dependencies_dir integration test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions