Skip to content

fix: handle FunctionNotFound for ECR-based image functions in sam sync#8603

Merged
bnusunny merged 1 commit intodevelopfrom
fix/issue-8381-sam-sync-ecr-image-functions
Mar 6, 2026
Merged

fix: handle FunctionNotFound for ECR-based image functions in sam sync#8603
bnusunny merged 1 commit intodevelopfrom
fix/issue-8381-sam-sync-ecr-image-functions

Conversation

@bnusunny
Copy link
Contributor

Issue

Fixes #8381

Description

sam sync --watch fails with FunctionNotFound when a nested stack contains a Lambda function with PackageType: Image that uses an ECR URI for ImageUri without DockerContext metadata.

Root Cause

  1. _add_code_triggers() iterates over all resource IDs from the template
  2. For image functions, it creates a LambdaImageCodeTrigger, which calls SamFunctionProvider.get()
  3. However, SamFunctionProvider._extract_functions() intentionally skips image functions with ECR URIs but no DockerContext metadata (since they can't be built locally)
  4. This causes SamFunctionProvider.get() to return None, raising FunctionNotFound

Solution

Catch FunctionNotFound alongside ResourceNotFound in _add_code_triggers(), allowing sam sync to 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: Added FunctionNotFound to exception handling
  • tests/unit/lib/sync/test_watch_manager.py: Added test for FunctionNotFound handling

Testing

  • Added unit test test_add_code_triggers_function_not_found

@bnusunny bnusunny requested a review from a team as a code owner January 28, 2026 00:21
@bnusunny bnusunny closed this Jan 28, 2026
@bnusunny bnusunny reopened this Jan 28, 2026
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.
@bnusunny bnusunny force-pushed the fix/issue-8381-sam-sync-ecr-image-functions branch from 73641e2 to d147e0a Compare January 28, 2026 02:00
@bnusunny bnusunny added this pull request to the merge queue Mar 6, 2026
Merged via the queue into develop with commit 32ed1d9 Mar 6, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: sam sync fails for Docker Image Functions - FunctionNotFound

3 participants