Skip to content

feat(sync): add --force-upload flag to control S3 upload dedup#9008

Open
vishwakt wants to merge 1 commit into
aws:developfrom
vishwakt:feat/sync-force-upload-flag
Open

feat(sync): add --force-upload flag to control S3 upload dedup#9008
vishwakt wants to merge 1 commit into
aws:developfrom
vishwakt:feat/sync-force-upload-flag

Conversation

@vishwakt
Copy link
Copy Markdown

Which issue(s) does this change fix?

Closes #8168

Why is this change necessary?

sam sync currently hardcodes force_upload=True in three places. That bypasses the SHA-based dedup inside S3Uploader.upload_with_dedup, so every sync re-zips and re-uploads every artifact to S3 even when nothing has actually changed. The original issue reports a 20%+ (~90s) speedup per run from disabling this on a fork.

How does it address the issue?

Exposes --force-upload on sam sync, defaulting to False (matching the default on sam deploy and sam package), and threads the flag through every code path that was previously hardcoded:

  1. samcli/commands/sync/command.py — replaces force_upload=True in PackageContext(...) and DeployContext(...) with the new option.
  2. samcli/lib/sync/flows/zip_function_sync_flow.py — the S3Uploader constructed for oversized lambda zips now reads force_upload from self._deploy_context.force_upload instead of hardcoding True. This was the third code path that defeated the dedup.
  3. Reuses the existing force_upload_option() decorator from samcli/commands/_utils/options.py, so help text, click metadata, and config-file plumbing are consistent with sam deploy / sam package.
  4. schema/samcli.json was regenerated via python -m schema.make_schema and now lists force_upload as a sync parameter.

Users who actually want the old behavior can pass --force-upload.

What side effects does this change have?

  • Default behavior change. Without --force-upload, sam sync will now skip uploading artifacts whose SHA already exists in S3 — which is what the issue requester (and the maintainer who welcomed a PR) asked for. Backward-compatible toggle via the new flag.
  • No change to non-sync commands.
  • No new dependencies or schema breaking changes; the schema gained one optional boolean property.

Tests

  • tests/unit/commands/sync/test_command.py — existing assertions updated from force_upload=True to force_upload=self.force_upload, plus a new parameterized test (test_force_upload_flag_propagates_to_package_and_deploy_contexts) covering both True and False and asserting the value reaches both PackageContext and DeployContext.
  • tests/unit/lib/sync/flows/test_zip_function_sync_flow.py — new parameterized test (test_s3_uploader_uses_deploy_context_force_upload) confirming the S3Uploader is constructed with deploy_context.force_upload for both values.
  • tests/unit/commands/samconfig/test_samconfig.pydo_cli arg-order assertion updated for the new positional parameter.
  • Full unit suite passes locally: 9131 passed, 25 skipped.
  • black --check setup.py samcli tests schema and ruff check samcli schema are both clean locally.

Mandatory Checklist

  • Review the generative AI contribution guidelines
  • Add input/output type hints to new functions/methods
  • Write design document if needed (not needed — surface-level flag mirroring an existing pattern in sam deploy / sam package)
  • Write/update unit tests
  • Write/update integration tests (happy to add if maintainers want — would live under tests/integration/sync/)
  • Write/update functional tests if needed
  • make pr passes locally (black --check, ruff check, python -m schema.make_schema, full unit suite)
  • make update-reproducible-reqs if dependencies were changed (no dep changes)
  • Write documentation (help text on the flag is auto-generated by force_upload_option; no separate docs file in this repo for this command)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

`sam sync` previously hardcoded `force_upload=True` in three places,
which bypassed the SHA-based dedup in `S3Uploader.upload_with_dedup`
and caused every sync to re-upload all artifacts even when nothing
had changed. Issue aws#8168 reports a 20%+ (90+ second) speedup from
toggling this off in a fork.

Expose `--force-upload` on `sam sync` (default False, matching
`sam deploy`'s default) and thread it through:

- PackageContext and DeployContext, replacing the two hardcoded
  `True` values in `samcli/commands/sync/command.py`.
- The S3Uploader instantiation in ZipFunctionSyncFlow now reads
  `force_upload` from `self._deploy_context.force_upload` so the
  flag actually controls the oversized-zip upload path too.

Schema regenerated. Unit tests updated to assert the flag flows
through PackageContext, DeployContext, and the ZipFunctionSyncFlow
S3 upload path for both True and False values.

Closes aws#8168
@vishwakt vishwakt requested a review from a team as a code owner May 14, 2026 18:12
@github-actions github-actions Bot added area/sync sam sync command area/schema JSON schema file pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/schema JSON schema file area/sync sam sync command pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: add flag to control force_upload option in sam sync

1 participant