Skip to content

TestServer: add SeedSSMParameter() helper to pre-populate public AWS SSM paths for AMI discovery tests #267

Closed

Description

@scttfrdmn

Summary

When testing code that calls AWS AMI discovery via SSM Parameter Store (the standard AWS pattern using /aws/service/canonical/..., /aws/service/ami-amazon-linux-latest/..., etc.), there is currently no way to pre-populate those paths in a TestServer without making raw HTTP calls to the SSM endpoint.

A TestServer.SeedSSMParameter(name, value string) helper would make it easy to seed these paths before running tests.

Use Case

Prism's LaunchInstance resolves AMI IDs by calling ssm.GetParameter with paths like:

/aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id
/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
/aws/service/debian/release/12/latest/amd64

In tests against a real AWS account these resolve to actual AMI IDs. Against a fresh TestServer, GetParameter returns a not-found error and the launch fails before RunInstances is ever called.

The workaround today is calling ssm.PutParameter via the SDK client before running the test, but that requires constructing a full SSM client just for setup. A helper on TestServer would be much cleaner:

func TestSubstrateLaunchInstance(t *testing.T) {
    ts := substrate.StartTestServer(t)

    // Pre-seed AMI IDs that LaunchInstance will look up via SSM
    ts.SeedSSMParameter("/aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id", "ami-ubuntu2404")
    ts.SeedSSMParameter("/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64", "ami-al2023x86")

    // Now LaunchInstance can resolve AMIs and call RunInstances
    manager := setupManager(t, ts)
    instance, err := manager.LaunchInstance(req)
    // ...
}

Current Workaround

ssmClient := ssm.NewFromConfig(cfg)
ssmClient.PutParameter(ctx, &ssm.PutParameterInput{
    Name:  aws.String("/aws/service/canonical/ubuntu/server/24.04/..."),
    Value: aws.String("ami-ubuntu2404"),
    Type:  types.ParameterTypeString,
})

This works but requires the test to set up its own SSM client just for seeding, adding boilerplate to every test that needs AMI resolution.

Proposed API

// On TestServer
func (ts *TestServer) SeedSSMParameter(name, value string)

// Optionally, a batch variant
func (ts *TestServer) SeedSSMParameters(params map[string]string)

The parameters would be injected directly into the SSM plugin's in-memory store, bypassing the HTTP layer entirely (same pattern used by other in-memory stores in Substrate).

Context

This is the last remaining blocker for TestSubstrateLaunchInstance and TestSubstrateEBSAttachDetach in scttfrdmn/prism. Issues substrate#260 and substrate#261 are fixed in v0.45.10 — IAM and SSM tests now pass. Only the AMI discovery seeding is missing.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions