Repository navigation
Description
Split from #183. Steps 3–7 of that issue, deferred until #226 gives an accurate rate a consumer — per #183's own framing: "Getting real prices into a calculator no code calls is the most expensive way to change nothing."
Do not start this before #226. Not a process preference: without an observable output there is no way to tell a correct fetch from the failure mode that killed the last attempt (see below), and the traps here are ones that return plausible-shaped wrong numbers rather than errors.
What already landed
internal/awsrates is the single rate table, verified against the live Pricing API by an integration test that re-reads 23 rates (#220, #225). So this issue is a single-site change — swap the table's source — rather than the five-site change it would have been.
Why the previous attempt failed
#161 deleted a "Pricing API integration" that was not partial: its parser matched products on human-readable storage-class names that do not appear in Pricing API payloads, and both cost extractors ignored their arguments and returned hardcoded constants. Enabling use_pricing_api fetched a multi-megabyte JSON document over HTTP and discarded it in favour of 0.023.
It would have passed against any hand-written mock, because a mock is built from the same assumptions as the parser. That is why the emulator matters here specifically.
Verified traps, carried over from #183
productFamilyis absent from 315 of 381 S3 products. Any filter or switch keyed on it silently drops 83% of the catalog. This is what broke the deleted parser.usagetypeis the only stable 1:1 key —USW2-Requests-Tier1,USW2-TimedStorage-ByteHrs. Match on it, never onstorageClassor product descriptions.us-west-2is not a Pricing API endpoint. The API is atapi.pricing.us-east-1.amazonaws.comandapi.pricing.ap-south-1.amazonaws.com.EndpointResolverV2templates any well-formed region into a hostname, so a wrong region gives an opaque DNS failure rather than a validation error. Validate against the two known endpoints before constructing the client. The region whose prices you want is a filter value, not the endpoint.productFamily=Storage+volumeType='Glacier Deep Archive'returns a staging SKU at 21× the real rate. The trap that makes a naive implementation worse than the static table it replaces: it looks like success and is off by a factor that would dominate any report it appears in. Every fetched rate needs a per-tier sanity band, and a rate outside its band must be rejected and logged — never used.pricePerUnitvalues are strings, and a SKU can carry multiplepriceDimensionswithendRange: "Inf". Tiered pricing is normal.service/pricingforces smithy-go ≥1.26.0. Itsendpoints/private/bddimport is absent from the pinned v1.24.0, and the bump also movesservice/s3andaws-sdk-go-v2— a dependency change touching the data path, so it wants its own commit and a full-racerun before any pricing code lands on top of it.
Hot-path constraint, non-negotiable
GetTierPricing is reachable from a filesystem read: GetObject → CostOptimizer.RecordAccess → calculateObjectCost.
atomic.Pointer[RateTable], swapped whole. No lock on the read path.- Refresh from a background ticker only. Never fetch synchronously from a filesystem operation.
- A pricing failure must never fail a filesystem operation. Stale rates, or the bundled snapshot — never an error propagated to a read. The cost feature is advisory; the filesystem is not.
Three sources, in order
GetProductsviaservice/pricing, on a ticker. Daily is ample; S3 list prices move rarely.- The public offer file (
https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonS3/current/index.json) as an unauthenticated fallback. This matters more than it sounds:GetProductsneedspricing:GetProductsIAM permission, which a mount's credentials usually will not have. Without the fallback the feature is off for most users. - The bundled snapshot —
internal/awsratesas it stands, regenerated by//go:generate. Always available, no network dependency, and what makes "a pricing failure cannot fail a read" trivially true rather than carefully true.
Region
Step 7 of #183, and the reason #226 must not publish region-labelled cost metrics before this lands: every rate today is us-east-1, so region: us-west-2 yields us-east-1 numbers labelled us-west-2. Fix by filtering on the configured region, or refuse to label output with a region whose rates were not fetched. Needs per-region rates to fix rather than to document, which is why it is here and not in #226.
Testing
internal/testaws runs the real S3 backend against an in-process substrate endpoint. Substrate has no pricing plugin — GetProducts returns 501 — so the fidelity requirements are filed upstream, and they are exactly the traps above:
PriceListas[]stringof raw JSON, not decoded objectspricePerUnitvalues as strings- at least one SKU with multiple
priceDimensionsandendRange: "Inf" productFamilyomitted on some SKUs
Also filed upstream: extractRegionFromHost returns "pricing" instead of the region for api.pricing.<region>.amazonaws.com.
A hand-written mock cannot serve here, for the reason CLAUDE.md gives and #161 demonstrated.
Activity