fix: handle FunctionNotFound for ECR-based image functions in sam sync#8603
Open
fix: handle FunctionNotFound for ECR-based image functions in sam sync#8603
Conversation
Fixes #8381 When sam sync --watch encounters an image function with an ECR URI but no DockerContext metadata, SamFunctionProvider skips it (since it can't be built locally). However, CodeTriggerFactory still tries to create a trigger for it, causing LambdaImageCodeTrigger to raise FunctionNotFound. This change catches FunctionNotFound alongside ResourceNotFound in _add_code_triggers(), allowing sam sync to gracefully skip these functions with a warning instead of crashing.
73641e2 to
d147e0a
Compare
reedham-aws
approved these changes
Feb 3, 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.
Issue
Fixes #8381
Description
sam sync --watchfails withFunctionNotFoundwhen a nested stack contains a Lambda function withPackageType: Imagethat uses an ECR URI forImageUriwithoutDockerContextmetadata.Root Cause
_add_code_triggers()iterates over all resource IDs from the templateLambdaImageCodeTrigger, which callsSamFunctionProvider.get()SamFunctionProvider._extract_functions()intentionally skips image functions with ECR URIs but noDockerContextmetadata (since they can't be built locally)SamFunctionProvider.get()to returnNone, raisingFunctionNotFoundSolution
Catch
FunctionNotFoundalongsideResourceNotFoundin_add_code_triggers(), allowingsam syncto gracefully skip these functions with a warning instead of crashing. This is consistent with how S3-based functions are already handled.Changes
samcli/lib/sync/watch_manager.py: AddedFunctionNotFoundto exception handlingtests/unit/lib/sync/test_watch_manager.py: Added test forFunctionNotFoundhandlingTesting
test_add_code_triggers_function_not_found