Skip to content

Bug: sam build --cached fails with PythonUvBuilder (--beta-features) #8838

Closed

Description

@tomaDev

Description

sam build --cached --beta-features fails with PythonUvBuilder:CopyDependencies - [Errno 2] No such file or directory when using the python-uv builder. The cached build deletes the .aws-sam/build/<FunctionName> directory but fails to recreate it before copying dependencies.

This happens both on a cold cache (no prior cached build) and on a warm cache (after a successful sam build --beta-features).

Steps to reproduce

# Minimal repro: any SAM project with 2+ Python functions using python-uv builder
sam build --beta-features          # succeeds
sam build --cached --beta-features # fails

Observed result

Starting Build use cache
Manifest is not changed for (MyFunction), running incremental build
Building codeuri: /path/to/src/my_function runtime: python3.14 architecture: arm64 functions: MyFunction
Auto-detected manifest file: /path/to/src/my_function/requirements.txt
 Running PythonUvBuilder:CopyDependencies

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

Expected result

sam build --cached --beta-features should succeed, reusing cached dependencies when the manifest hasn't changed and only re-copying source files.

Notes

  • sam build --beta-features (without --cached) works fine
  • sam build --parallel --beta-features (without --cached) works fine
  • sam build --cached --parallel --beta-features also fails with the same error
  • The issue appears to be that the cached build path removes the build output directory (.aws-sam/build/<FunctionName>) but the PythonUvBuilder:CopyDependencies step expects it to already exist

Environment

SAM CLI version: 1.156.0
Python: 3.14.3
uv: 0.10.12
OS: macOS 26.3 (aarch64-apple-darwin)

Activity

  1. added
    area/build
    stage/bug-repro
    on Mar 23, 2026
  2. vicheey commented on Mar 27, 2026

    @vicheey
    Contributor

    I was able to reproduce the issue with on SAM CLI 1.156.0.

  3. vicheey commented on Mar 27, 2026

    @vicheey
    Contributor

    This issue may requires fix in aws-lambda-builders package rather than in aws-sam-cli package.

  4. tomaDev commented on Mar 30, 2026

    @tomaDev
    Author

    @vicheey A quick dup check of aws-lambda-builders issues doesn't find it. Should I open it as a separate issue, or are you maybe aware of a relevant thread there?

  5. tomaDev commented on Apr 26, 2026

    @tomaDev
    Author

    Filed upstream at aws-lambda-builders per @vicheey's pointer: aws/aws-lambda-builders#864 — repro confirmed on SAM CLI 1.158.0 + uv 0.11.7 + Python 3.14.

  6. tomaDev commented on Sep 5, 2026

    @tomaDev
    Author

    Closing: this is fixed.

    Root cause was in aws-lambda-builders, not SAM CLI, as @vicheey suspected. On the incremental path the uv workflow's CopyDependencies step wrote into .aws-sam/build/<FunctionName> after SAM CLI had removed it and before anything recreated it.

    Fix: aws/aws-lambda-builders#870 (closes aws/aws-lambda-builders#864), released in aws-lambda-builders v1.65.0 on 2026-06-09. SAM CLI picked it up in #9069 and shipped it in v1.162.0 (2026-06-10). Any SAM CLI >= 1.162.0 has the fix; current release is 1.166.1.

    Verified today against a develop-based build of SAM CLI 1.166.1 (aws-lambda-builders 1.67.0, uv 0.12.10, Python 3.13 target, arm64, macOS) with a template of two python-uv functions using requirements.txt, which is the scenario from the report:

    Command Result
    sam build --beta-features succeeds
    sam build --cached --beta-features (cold cache) succeeds
    sam build --cached --beta-features (warm cache) succeeds, logs Manifest is not changed ... running incremental build and reuses dependencies
    sam build --cached --parallel --beta-features succeeds
    delete .aws-sam, then sam build --cached --beta-features succeeds

    Built artifacts contain the expected dependencies after each run.

    Related: #9113 adds python-uv support for Lambda layers, including --cached, which was hitting a different failure ('python-uv' runtime is not supported from the manifest hash) that the layer PR fixes on the SAM CLI side.

  7. github-actions commented on Sep 5, 2026

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    Comments on closed issues are hard for our team to see.
    If you need more assistance, please either tag a team member or open a new issue that references this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

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

    area/buildstage/bug-reprotype/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions