fix: sync command region handling and bucket region auto-detection#858
Open
gchait wants to merge 1 commit intopeak:masterfrom
Open
fix: sync command region handling and bucket region auto-detection#858gchait wants to merge 1 commit intopeak:masterfrom
gchait wants to merge 1 commit intopeak:masterfrom
Conversation
- Apply --source-region and --destination-region flags in sync command
* Modified getSourceAndDestinationObjects() to create separate storage
options for source and destination clients
* Matches the pattern already used in cp command
- Always auto-detect bucket region when bucket is specified
* Modified setSessionRegion() to call GetBucketRegion() regardless of
whether a region is configured in the AWS profile
* Falls back to configured region only when auto-detection fails
* Makes behavior consistent with AWS CLI
Fixes:
- sync command ignoring --source-region and --destination-region flags
- signature mismatch errors when AWS profile has a region configured
but bucket is in a different region
Author
|
Regarding the failing CI, I considered adding |
terryrankine
added a commit
to terryrankine/s5cmd
that referenced
this pull request
Mar 18, 2026
The sync command was ignoring --source-region and --destination-region flags because it used the same storageOpts for both clients. Now creates separate option copies with region overrides, matching the cp command's existing pattern. (peak#858) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 tasks
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.
Fix: Sync command region handling and auto-detection
Problem
This PR fixes two related issues with region handling in s5cmd:
Sync command doesn't respect
--source-regionand--destination-regionflags: While thecpcommand correctly applies these flags, thesynccommand ignores them, causing operations to fail when syncing between buckets in different regions.Region auto-detection fails when AWS profile has a region configured: When a profile specifies a region, the current code skips bucket region auto-detection. This causes signature mismatch errors when the actual bucket is in a different region than the profile's configured region.
Solution
1. Apply region flags in sync command (
command/sync.go)Modified
getSourceAndDestinationObjects()to create separate storage option objects for source and destination clients, applying the respective region flags before creating the clients. This matches the pattern already used in thecpcommand.2. Always auto-detect bucket regions (
storage/s3.go)Modified
setSessionRegion()to always perform bucket region auto-detection when a bucket is specified, regardless of whether a region is configured in the profile. This makes s5cmd's behavior consistent with AWS CLI.Changes:
GetBucketRegion()when a bucket name is providedThis approach aligns with AWS CLI's "it just works" philosophy, where cross-region operations work transparently.
Notes
The extra HEAD request for bucket region auto-detection is a minor overhead (one per bucket per session) that enables seamless cross-region operations, matching user expectations from AWS CLI.
Related Issues
Fixes issues where:
s5cmd sync --source-region us-east-1 --destination-region eu-west-1 's3://bucket1/*' s3://bucket2/would fail