Repository navigation
Description
Split out of #401, where it was reported alongside an unrelated feature request. The
reporter offered the split; this is that half.
Summary
extractRegionFromHost (emulator/parser.go:407) returns "pricing" — a service
name — for api.pricing.us-east-1.amazonaws.com, instead of us-east-1.
Root cause
Confirmed by reading emulator/parser.go:407-445. After stripping
.amazonaws.com, parts = ["api", "pricing", "us-east-1"]. Then:
- the
s3loop (:427-434) does not fire — nos3token; - the
execute-apibranch (:437-439) does not match —parts[1]ispricing; - so it falls through to the
"<service>.<region>"assumption at:441-444and
returnsparts[1], which is the second label of a three-label host.
This is not specific to pricing. Any api.<service>.<region> hostname is
mis-parsed the same way, and the function fails open: it returns a confident
wrong answer rather than an empty string, so a caller cannot tell a parse failure
from a real region.
Fix
Two parts, the second being the more valuable:
- Handle the
api.prefix: whenlen(parts) >= 3 && parts[0] == "api", return
parts[2]. - Make the function fail closed. An AWS region always looks like
xx-yyyy-N(optionally with a longer middle segment, e.g.us-gov-west-1,
ap-southeast-4). Validating the candidate against that shape before
returning it means an unrecognised host layout yields""— which callers
already handle via thedefaultRegionfallback at:404— instead of a
service name masquerading as a region.
Part 2 subsumes part 1 for this specific host and guards the whole class, so it is
worth doing even though part 1 alone closes the reported symptom.
Acceptance criteria
-
extractRegionFromHost("api.pricing.us-east-1.amazonaws.com")returnsus-east-1 -
extractRegionFromHost("api.pricing.ap-south-1.amazonaws.com")returnsap-south-1 - A candidate that is not region-shaped yields
""rather than a service name - Existing forms still parse:
s3.us-west-2…,mybucket.s3.us-east-1…,
{apiId}.execute-api.{region}…,<service>.<region>…, and the no-region
global forms - Table-driven test covering all of the above, including
us-gov-west-1and a
bare<service>.amazonaws.com -
CHANGELOG.mdentry under### Fixed
Refs #401 (the Price List Query API emulation half).
Activity
scttfrdmn commentedon Jul 31, 2026
Split out of #401 per the reporter's offer. See #401 for the Price List Query API
emulation half.
fix(parser): validate the region parsed from Host and handle api.* ho…
feat(pricing): emulate the Price List Query API over a real offer cor…
chore(release): v0.80.0 (#423)