feat(local): add --no-watch flag to disable hot reload#8196
feat(local): add --no-watch flag to disable hot reload#8196roger-zhangg wants to merge 14 commits into
Conversation
|
DO NOT MERGE. |
The base branch was changed.
|
This failing test seems unrelated, but will take a look |
|
also passed on my local |
|
What is the reason that we no longer allow customers to provide a list of files/dirs to be ignored? It seems like that was the original intention. |
The root cause was actually not that. Originally the assumed root cause was few node lib is constantly changing when function is invoking and therefore triggering our file watcher, but then it turns out it's just the file watcher is somehow lagging and it picks up the filechanges way later than it should be. So the lib changes are done in build, which should be a legit change that should be picked up. For what here is fixing, is in some sam project setup, it might have multiple lambda function sharing a same code dir (like a same file with different function as entrypoint). When we are doing Instead, providing the |
Resolve conflicts and address PR feedback: - Use kwargs (`function_logical_ids`, `no_watch`) on `RefreshableSamFunctionProvider` instead of brittle positional `args.extend(...)` (addresses valerena's review concern about uncaught errors when --no-watch is used without --warm-containers). - When --no-watch is supplied without --warm-containers, log a warning, ignore the flag, and never forward `no_watch` to the cold-mode `SamFunctionProvider` (which doesn't accept it). - Combine the merge-conflicting changes in `WarmLambdaRuntime.create()`: keep develop's threading lock + container_dns refactor and gate observer.watch/start/unwatch behind `self._observer is not None` so --no-watch is safe. - Update --no-watch help text to clarify the --warm-containers prerequisite and the use case from issue aws#8782 (file watching causes high CPU/IO with Microsoft Defender / large monorepos / .sandbox dirs). - Regenerate schema/samcli.json. - Add unit tests covering: provider kwarg routing for warm mode, warning + skip for cold mode, RefreshableSamFunctionProvider observer skipped with no_watch=True, and WarmLambdaRuntime no_watch lifecycle no-ops.
Apply black formatting after merge of develop into hot-swap-fix.
- Add no_watch docstring entry to RefreshableSamFunctionProvider. - Initialize self._observer = None up front in RefreshableSamFunctionProvider so the type annotation is unconditional and the no-watch branch is implied. - Drop incidental whitespace-only hunks (blank line in invoke_context.__enter__, blank line in SingletonFileObserver.__init__) flagged during review.
Which issue(s) does this change fix?
#8782
Why is this change necessary?
The AWS SAM CLI file watcher caused unstable behavior during local development with
--warm-containers:CodeUri— a single change in any function falsely invalidated all of them, killing every running warm container and demoting back to LAZY mode. Reproed in LoopBack apps that auto-create temporary.sandboxdirectories (8+ minute startup times).How does it address the issue?
Adds a
--no-watchflag tosam local start-apiandsam local start-lambda. When supplied with--warm-containers, SAM CLI skips creating any file observers (template watcher and the per-functionLambdaFunctionObserver). Local code or template changes will not restart the running container — stop and rerun the command to pick up changes.The flag is forwarded as a kwarg through
RefreshableSamFunctionProviderandWarmLambdaRuntime. Withno_watch=True, no observer is constructed, and everywatch/unwatch/start/stopcall becomes a guarded no-op.Also adds debug logging around
LambdaFunctionObserverlock acquire / resource processing to help triage future watcher issues.What side effects does this change have?
--no-watchonly takes effect with--warm-containers. When supplied without warm containers, the flag is ignored and aWARNINGis logged. The cold-modeSamFunctionProvider(which doesn't acceptno_watch) never receives the flag — addresses the earlier review concern about an uncaught error in that path.no_watch: Optional[bool] = FalseonInvokeContext,RefreshableSamFunctionProvider, andWarmLambdaRuntime. Defaults preserve existing behavior; no caller is required to update.WarmLambdaRuntime.__init__docstring (warm_containers→ current parameters) flagged in earlier review.no_watchentry inschema/samcli.jsonfor bothlocal_start_apiandlocal_start_lambda.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.