fix(local): warn when CodeUri path does not exist before mounting#9120
Open
cesar32az wants to merge 1 commit into
Open
fix(local): warn when CodeUri path does not exist before mounting#9120cesar32az wants to merge 1 commit into
cesar32az wants to merge 1 commit into
Conversation
When running sam local invoke, start-api or start-lambda with a CodeUri (or layer ContentUri) that does not exist on the local machine, the path was silently mounted as an empty directory in the container. The invocation then failed with a secondary error (import or handler not found) that hides the real problem. Log a warning in LambdaRuntime._get_code_dir when the resolved code path does not exist, pointing the user at the CodeUri/ContentUri and suggesting sam build, so the root cause is visible before the container starts. Fixes aws#1754
roger-zhangg
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does this change fix?
#1754
Why is this change necessary?
When running
sam local invoke,start-apiorstart-lambdawith aCodeUri(or layerContentUri) that does not exist on the local machine, the path is silently mounted as an empty directory in the container. The invocation then fails with a secondary error inside the container (import/handler not found) that hides the real problem. Issue #1754 was marked open for contributors by a maintainer.How does it address the issue?
LambdaRuntime._get_code_dirnow logs a warning when the resolved code path does not exist, before the container is started:Since
_get_code_diris used both for function code and for layers (via_unarchived_layer), the warning covers both cases. Behavior is otherwise unchanged: the path is still returned as is, exactly as documented in the method docstring.Verified end-to-end with Docker:
sam local invokeon a template whoseCodeUripoints to a missing directory now prints the warning right after "Invoking app.handler (python3.12)".What side effects does this change have?
None. Only a warning log line is added; no control flow changes.
code_pathvalues that exist (directories, zip/jar archives) behave exactly as before, and the full unit suite passes.Mandatory Checklist
PRs will only be reviewed after checklist is complete
TestLambdaRuntime_get_code_dir: warning emitted for a missing path, no warning for an existing path)make prpasses (schema, black-check, ruff, mypy: no issues in 1375 files; unit suite: 9287 passed, coverage 94.16% >= 94%)make update-reproducible-reqsif dependencies were changed (no dependency changes)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.