Repository navigation
fix(ec2): RunInstances must reject invalid MinCount/MaxCount (#431) - #438
Merged
Merged
Conversation
Both counts were parsed with strconv.Atoi's error discarded and anything <= 0 clamped up to 1, so MinCount=0 launched an instance where real EC2 fails the request, and MinCount=abc launched one too. That is worse than a missing error: it is a confidently wrong answer, so a consumer asserting on the launched count got a green run for a request AWS rejects. A count that is present but unparseable or below 1, or a MinCount above MaxCount, is now InvalidParameterValue / HTTP 400. Absence still defaults, and an absent MaxCount defaults to MinCount rather than to 1, so a request asking for three no longer risks launching one. Presence is deliberately not required. Both are required members that fail client-side in every typed SDK, so a consumer bug there cannot reach the wire, while requiring presence here would break hand-built form-encoded requests — substrate's own tests and betty_cfn.go's CFN path. Values are different: the query protocol carries them as strings, botocore's ParamValidator accepts MinCount=0 and MinCount=3/MaxCount=1 unchanged, and aws-sdk-go-v2's validateOpRunInstancesInput checks only for nil. That split is why one is validated and the other is not. The codes were verified against the RunInstances reference rather than guessed, which changed the answer: the reference documents no action-specific error for these and defers to the common errors, and InvalidParameterCombination is defined as "Parameters that must not be used together were used together" — which cannot describe two parameters AWS documents as used together. All three cases use InvalidParameterValue. #413 is why a plausible guess about an AWS error code is not good enough to ship. Only MaxCount reaches the launch loop: AWS launches "the largest possible number of instances above the specified minimum count" and substrate models no capacity ceiling, so that is always MaxCount and MinCount can only ever be satisfied. It is still validated, and still sets MaxCount's default. Both directions of the fix were verified by mutation: restoring the clamp fails all eight rejection rows, and defaulting MaxCount to 1 instead of MinCount fails the row that pins it. Closes #431
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Aug 1, 2026
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 #431
The defect
RunInstancesparsed both counts withstrconv.Atoi's error discarded and clamped anything<= 0up to 1:So
MinCount=0launched an instance where real EC2 fails the request, andMinCount=abclaunched one too. That is worse than a missing error — it is a confidently wrong answer. A consumer asserting on the launched count got a green run for a request AWS rejects.What changed
New
emulator/ec2_runinstances_counts.go. A count that is present but invalid now fails; a count that is absent still defaults.MinCount=0InvalidParameterValueMaxCount=0MinCount=-1MinCount=abcMinCount=3&MaxCount=1MinCount=2aloneMinCount=1&MaxCount=3The
MinCount=2row is the one behavior change beyond the errors: an absentMaxCountdefaults toMinCountrather than to 1, so a request asking for three no longer silently launches one.Why presence is not required
The declined half of #412 asked for a "quick pass for other required params". AWS marks both counts Required: Yes, but in every typed SDK they are required members that fail client-side —
MaxCount == nilissmithy.NewErrParamRequired("MaxCount")inaws-sdk-go-v2'svalidateOpRunInstancesInput, and botocore rejects the missing kwarg before serializing. A consumer bug there cannot reach the wire, so validating presence would catch an unreachable bug class while breaking every hand-built form-encoded request — which substrate's own tests andbetty_cfn.go's CFN path are.Values are the opposite. Verified empirically: botocore's
ParamValidatoracceptsMinCount=0,MinCount=3/MaxCount=1andMinCount=-1with zero validation errors, andaws-sdk-go-v2checks only fornil. Both reach the wire from ordinary typed code. That split is the whole justification for validating one and not the other.Error codes: verified, not guessed
Per CLAUDE.md, checked against the AWS reference — and the answer came out different from the issue's own guess:
InvalidParameterValueis documented as "A value that you provided for a parameter isn't valid" (HTTP 400) — exactly an out-of-range or unparseable count, given the documented constraint "Between 1 and the quota for the specified instance type".MinCount > MaxCountuses the same code rather than the plausible-lookingInvalidParameterCombination, which is defined as "Parameters that must not be used together were used together". That cannot describe two parameters AWS documents as used together; the defect is the value ofmaxCountrelative tominCount.#413 is why a plausible guess about an AWS error code is not good enough to ship — SDK callers match the literal string.
The upper bound is a per-account, per-instance-type quota substrate does not model, so it is not enforced.
Only MaxCount reaches the launch loop
resolveInstanceCountsreturns both, butrunInstancesdiscardsminCount. AWS "launches the largest possible number of instances above the specified minimum count", and substrate models no capacity ceiling, so the largest possible number is alwaysMaxCountandMinCountcan only ever be satisfied. It is still validated, and still setsMaxCount's default — which is all it can affect. The discard is commented as a decision rather than left as a silent drop.Tests
TestEC2_RunInstances_InstanceCounts, beside the #412 test, in two groups:DescribeInstancesreports nothing (a rejected launch must create nothing, or a consumer's cleanup path is wrong).RunInstancesresponse andDescribeInstances, including the two "absence still defaults" regression guards the issue asked for.Verified by mutation, not just by passing:
MaxCountto 1 instead ofMinCount→ the row pinning that fails.Blast radius
Zero. All 101 existing
RunInstancestest references useMinCount=1/MaxCount=1or omit both.betty_cfn.go:2054-2055passes"1"/"1".ec2_fleet.go:437-438passescountfor both but is guarded byif gotPerPool[i] > 0, so no zero can reachrunInstancesfrom the fleet path.Verification
gofmt·go build ./...·go vet ./...·golangci-lint run ./...(0 issues) ·make test(race) ·test/e2e·make docs-reference-check docs-versions— all green.Docs: new
### MinCount and MaxCountsection indocs/services.mdwith the behavior table and the code rationale; theRunInstancesops-table row cross-references it.