Repository navigation
fix(launch): --region pins the whole client, not just RunInstances (#276) - #278
Merged
Merged
Conversation
) spawn launch --region <r> could land the instance in the wrong region: the flag reached RunInstances (Launch copies the cfg + sets its region), but the client was built with LoadDefaultConfig and no region override, so caller-identity, pricing, and AMI/AZ resolution ran in the ambient AWS_REGION/profile region. When those came up empty, the latency-based auto-detector (detectBestRegion) could pick a third region — a --region us-west-2 launch observed landing in us-west-1. Add NewClientWithRegion(ctx, region) (config.WithRegion when non-empty; empty preserves the default chain for region-spanning commands). Use it in the flags, sweep, and batch-queue launch paths once the region is resolved, so every region-sensitive call uses the target region. Regression tests assert an explicit region beats ambient AWS_REGION, and empty falls back to the default chain. Fixes #276
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #276.
spawn launch --region us-west-2was observed launching in us-west-1 (neither the flag nor the ambientAWS_REGION=us-east-1).Root cause
The
--regionflag did reachRunInstances—Launch()copies the config and setscfg.Region = launchConfig.Regionfor the EC2 client. But the client itself was built viaaws.NewClient(ctx)→LoadDefaultConfig(ctx)with no region override, so the client's other region-sensitive calls (STSGetCallerIdentity, Pricing,DescribeImages/AZ resolution) ran in the ambientAWS_REGION/AWS_DEFAULT_REGION/profile region. And when region resolution came up empty on one of those paths, the latency-baseddetectBestRegionpicked the closest region — us-west-1 for a west-coast user — explaining the third-region surprise.Fix
aws.NewClientWithRegion(ctx, region): threadsconfig.WithRegion(region)intoLoadDefaultConfigwhen region is non-empty; empty preserves the default chain (for commands that legitimately span regions).RunInstances— is pinned to the target region.detectBestRegionstill only fires when no region is given; its own client stays default (it's measuring latency across all regions).Tests
TestNewClientWithRegion_PinsRegionOverAmbient— explicit region beatsAWS_REGION=us-east-1(the regression).TestNewClientWithRegion_EmptyFallsBackToAmbient— empty region uses the default chain.gofmt/vet/go test ./pkg/aws/+./cmd/green.Note: this is #276 only. #277 (SSM readiness gate +
--require-spored=falseearly-terminate) is separate; Symptom A has a clear fix (wait for SSM agent registration / SSH fallback), Symptom B needs a live repro.