Skip to content

parser: extractRegionFromHost returns the service name for api.<service>.<region> hosts #403

Closed

Description

@scttfrdmn

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 s3 loop (:427-434) does not fire — no s3 token;
  • the execute-api branch (:437-439) does not match — parts[1] is pricing;
  • so it falls through to the "<service>.<region>" assumption at :441-444 and
    returns parts[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:

  1. Handle the api. prefix: when len(parts) >= 3 && parts[0] == "api", return
    parts[2].
  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 the defaultRegion fallback 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") returns us-east-1
  • extractRegionFromHost("api.pricing.ap-south-1.amazonaws.com") returns ap-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-1 and a
    bare <service>.amazonaws.com
  • CHANGELOG.md entry under ### Fixed

Refs #401 (the Price List Query API emulation half).

Activity

  1. added this to the v0.79.0 milestone on Jul 31, 2026
  2. added
    type: bug
    area: server
    priority: medium
    on Jul 31, 2026
  3. scttfrdmn commented on Jul 31, 2026

    @scttfrdmn
    OwnerAuthor

    Split out of #401 per the reporter's offer. See #401 for the Price List Query API
    emulation half.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: serverpriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions