Skip to content

fix(launch): --region pins the whole client, not just RunInstances (#276) - #278

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/276-region-flag-ignored
Jul 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/276-region-flag-ignored

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #276. spawn launch --region us-west-2 was observed launching in us-west-1 (neither the flag nor the ambient AWS_REGION=us-east-1).

Root cause

The --region flag did reach RunInstances — Launch() copies the config and sets cfg.Region = launchConfig.Region for the EC2 client. But the client itself was built via aws.NewClient(ctx) → LoadDefaultConfig(ctx) with no region override, so the client's other region-sensitive calls (STS GetCallerIdentity, Pricing, DescribeImages/AZ resolution) ran in the ambient AWS_REGION/AWS_DEFAULT_REGION/profile region. And when region resolution came up empty on one of those paths, the latency-based detectBestRegion picked the closest region — us-west-1 for a west-coast user — explaining the third-region surprise.

Fix

  • New aws.NewClientWithRegion(ctx, region): threads config.WithRegion(region) into LoadDefaultConfig when region is non-empty; empty preserves the default chain (for commands that legitimately span regions).
  • Use it in the three launch paths (flags, parameter-sweep, batch-queue) after the region is resolved, so the whole client — not just RunInstances — is pinned to the target region.
  • detectBestRegion still only fires when no region is given; its own client stays default (it's measuring latency across all regions).

Tests

  • TestNewClientWithRegion_PinsRegionOverAmbient — explicit region beats AWS_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=false early-terminate) is separate; Symptom A has a clear fix (wait for SSM agent registration / SSH fallback), Symptom B needs a live repro.

)

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

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch.go 0.00% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ba95025 into main Jul 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/276-region-flag-ignored branch July 8, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spawn launch --region ignored; ambient AWS_REGION/resolution wins → instance in wrong region

1 participant