Skip to content

RunInstances: validate required parameters (ImageId) like AWS does #412

Closed

Description

@scttfrdmn

Summary

EC2Plugin.runInstances reads ImageId (emulator/ec2_plugin.go ~L230) but never validates it's non-empty. Real EC2 RunInstances rejects a call with no ImageId (and no launch template supplying one) with MissingParameter. Substrate accepts it and returns a running instance. Other required params in the same plugin are validated (KeyName, VpcId, CidrBlock, InstanceId all return MissingParameter/InvalidParameterValue), so this is a fidelity gap, not a design boundary — squarely "request/response error-code accuracy" per scope.md.

Why this matters (concrete)

In spore-host/spawn#70, the pool's worker-launch path built a LaunchConfig with an empty AMI (it bypassed the AMI auto-detect that the normal launch path does). On real AWS every worker failed with MissingParameter; against Substrate the launch "succeeded", so the bug shipped and only a paid smoke caught it. Validating ImageId would have turned this into a unit-test failure.

Proposed

In runInstances, when ImageId is empty AND no launch template / template ImageId resolves one, return:

&AWSError{Code: "MissingParameter", Message: "The request must contain the parameter ImageId", HTTPStatus: 400}

Mirror AWS wording where practical. Consider a quick pass for any other RunInstances params AWS treats as required so the emulator's reject-set matches (ImageId is the high-value one for the launch path).

Acceptance

  • RunInstances with no ImageId (and no template supplying one) → MissingParameter, HTTP 400.
  • RunInstances with a valid ImageId (or a launch template that carries one) → unchanged.

Scope note

Error-code fidelity on an existing operation; no workload execution. Consistent with the required-parameter validation the plugin already does elsewhere.

Reported from spore-host/spawn#70 pooled-execution validation.

Activity

  1. added
    type: bug
    priority: high
    on Aug 1, 2026
  2. added this to the v0.81.0 milestone on Aug 1, 2026
  3. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed and closed by #425 (v0.81.0, unreleased). RunInstances now rejects a launch
    that resolves no AMI with MissingParameter / "The request must contain the parameter
    ImageId" / HTTP 400 — the exact shape you asked for, via the existing
    ec2MissingParameter helper.

    The check runs after launch-template resolution, not on request entry. AWS
    documents ImageId as "Required: No" precisely because a launch template may supply
    it, so a check at the top would reject a valid launch that names a template carrying
    an AMI. Positioned post-resolution, the condition reads as the actual AWS rule: no
    AMI resolved from any source
    . Test rows pin both directions, including the case
    where a template resolves but carries no ImageId (400 — nothing resolved).

    Scope is strictly emptiness — no ami- format validation. There's no image-ID kind
    in the resource-ID validator today and around a dozen existing tests use non-hex IDs
    like ami-base and ami-test; adding format checks is a separate decision.

    On the "quick pass for other required parameters" — declining, and why it's not arbitrary

    AWS marks only MinCount and MaxCount as required on RunInstances, and in every
    typed SDK those are required members: int32 in Go, required kwargs in botocore's
    validation layer. A consumer bug there fails client-side and never reaches the wire,
    so validating them here would catch a bug class that is already unreachable — while
    breaking hand-built form-encoded requests, which is what a good number of substrate's
    own tests are.

    ImageId is different in a way that is the whole reason your bug shipped: it's an
    optional *string, so aws.String("") serializes as absent from the wire and
    reaches the service. Client-side validation cannot catch it; only the service can.
    That asymmetry — optional-typed but service-required-in-effect — is where the real
    fidelity gaps live, and it's a better filter for "what should substrate validate"
    than the required/optional column in the docs.

    There is a non-breaking version of your suggestion, though, and it's worth doing:
    reject MinCount/MaxCount that are present but unparseable or < 1 with
    InvalidParameterValue, while leaving absence defaulted as it is now. That catches
    a real wire-reachable mistake without breaking anything that omits them. I'll file it
    separately rather than widen this issue.

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: ec2priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions