kubernetes/kops · error
error creating LaunchTemplate %q: %v
Error message
error creating LaunchTemplate %q: %v
What it means
RenderAWS creates a new EC2 launch template with CreateLaunchTemplate when the task has no existing ID (or a new name). The error fires when the API call errors OR when the response contains no LaunchTemplate (AWS accepted but returned nothing usable). The wrapped AWS error text carries the real cause.
Source
Thrown at upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go:170
data.CreditSpecification = &ec2types.CreditSpecificationRequest{
CpuCredits: t.CPUCredits,
}
}
// @step: attempt to create the launch template
if a == nil {
input := &ec2.CreateLaunchTemplateInput{
LaunchTemplateName: t.Name,
LaunchTemplateData: data,
TagSpecifications: []ec2types.TagSpecification{
{
ResourceType: ec2types.ResourceTypeLaunchTemplate,
Tags: tags,
},
},
}
output, err := c.Cloud.EC2().CreateLaunchTemplate(ctx, input)
if err != nil || output.LaunchTemplate == nil {
return fmt.Errorf("error creating LaunchTemplate %q: %v", fi.ValueOf(t.Name), err)
}
e.ID = output.LaunchTemplate.LaunchTemplateId
} else {
input := &ec2.CreateLaunchTemplateVersionInput{
LaunchTemplateName: t.Name,
LaunchTemplateData: data,
}
if version, err := c.Cloud.EC2().CreateLaunchTemplateVersion(ctx, input); err != nil {
return fmt.Errorf("error creating LaunchTemplateVersion: %v", err)
} else {
newDefault := strconv.FormatInt(*version.LaunchTemplateVersion.VersionNumber, 10)
input := &ec2.ModifyLaunchTemplateInput{
DefaultVersion: &newDefault,
LaunchTemplateId: version.LaunchTemplateVersion.LaunchTemplateId,
}
if _, err := c.Cloud.EC2().ModifyLaunchTemplate(ctx, input); err != nil {
return fmt.Errorf("error updating launch template version: %w", err)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Read the wrapped AWS error: InvalidLaunchTemplateName.AlreadyExists means reuse/delete the existing template.
- If UserData too large, shrink it (or move content to a bootstrap asset fetched at runtime).
- Validate instance type / block device mappings are valid EC2 values.
- Ensure IAM permissions include ec2:CreateLaunchTemplate; retry on throttling.
Example fix
// before: 70KB embedded userdata
UserData: aws.String(bigScript)
// after: compress/gzip or serve script via S3 and keep userdata small
UserData: aws.String("#!/bin/bash\naws s3 cp s3://bucket/bootstrap.sh - | bash") Defensive patterns
Strategy: try-catch
Validate before calling
// keep userdata under the 64KB EC2 limit before apply size=$(wc -c < userdata.sh); test $size -lt 65536 || echo "userdata too large"
Try / catch
if strings.Contains(err, "AlreadyExists") { adopt/delete the existing template } else if strings.Contains(err, "RequestLimitExceeded") { backoff and retry } else if strings.Contains(err, "UnauthorizedOperation") { fix IAM ec2:CreateLaunchTemplate } Prevention
- Keep rendered userdata < 64KB (gzip or fetch payload from S3).
- Grant ec2:CreateLaunchTemplate to the kops role.
- Validate instance type and block device mapping values against EC2 limits.
When it happens
Trigger: RenderAWS on a launchtemplate task with e.ID == nil where EC2 CreateLaunchTemplate fails: invalid launch template data (bad block device mapping, oversized userdata >64KB, invalid instance type), duplicate name, throttling, or unauthorized.
Common situations: UserData exceeding the 64KB EC2 limit; invalid device mappings from bad volume config; IAM missing ec2:CreateLaunchTemplate; template name colliding with an existing one in the account/region.
Related errors
- timed out waiting for volume to detach
- error listing AutoScaling LaunchTemplates: %v
- error deleting ec2 LaunchTemplate %q: %v
- error creating LaunchTemplateVersion: %v
- error updating launch template version: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/56d66c3e34f0cefc.
Report an issue: GitHub.