Skip to content

client.Launch sends empty KeyName to RunInstances; headless/SSM launch fails with 'keyPairNames should not be blank' #130

Closed

Description

@scttfrdmn

Summary

After the user-data base64 fix (#127), the headless launcher.Provision path now fails one step later at RunInstances:

InvalidParameterValue: Invalid value '' for keyPairNames. It should not be blank

client.Launch unconditionally sets KeyName: aws.String(launchConfig.KeyName) (client.go:299). When KeyName is empty — the normal headless case, where lagotto launches with no SSH key and relies on SSM — this sends an empty-but-present KeyName string, which EC2 rejects. An omitted KeyName is valid (launch with no key pair); an empty-string KeyName is not.

This is the lagotto#19 design intent, per the closing comment on that issue:

SSM-only is fine (the spored role attaches AmazonSSMManagedInstanceCore), so no on-disk SSH key is required in Lambda.

So launcher.Provision deliberately doesn't set up an SSH key — but client.Launch then can't express "no key pair" because it always passes the field.

Reproduction

# spawn v0.44.1, lagotto v0.39.1
lagotto watch g5.12xlarge --action spawn --spawn-config sam.yaml --regions us-west-2 --ttl 7d
lagotto poll --verbose
# → Match found → base64 OK now → launch: InvalidParameterValue: Invalid value '' for keyPairNames

Fix

In client.Launch, only set KeyName on the RunInstancesInput when non-empty:

runInput := &ec2.RunInstancesInput{
    // ... other fields ...
}
if launchConfig.KeyName != "" {
    runInput.KeyName = aws.String(launchConfig.KeyName)
}

(Currently client.go:299 sets it inline unconditionally.) Omitting the field is the AWS-supported way to launch without a key pair, which is exactly what the SSM-only headless path needs.

Impact

Second blocker (after #127) on the lagotto#19 "watch → launch → run → stop" flow. With both fixed, a headless capacity-triggered launch should finally succeed end-to-end. Found in the same BuckAI/fieldwork Tutorial 01 scenario (auto-launch SAM inference on g5.12xlarge when us-west-2 capacity appears).

Version

spawn v0.44.1, lagotto v0.39.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions