Error: Build 'amazon-ebs' errored: Error creating AMI: InvalidAMIName.Malformed
Fixes Packer failing at AMI creation because the ami_name contains illegal characters. For engineers whose builds run to completion then fail at the final AMI step, the fix is sanitizing the name.
Error: Build 'amazon-ebs' errored: Error creating AMI: InvalidAMIName.Malformed
TL;DR
Your ami_name contains characters AWS rejects (like + or spaces). Restrict it to letters, numbers, ( ) . - / _, 3-128 chars, and rebuild.
The error
==> amazon-ebs: Error creating AMI: InvalidAMIName.Malformed: AMI names must be between 3 and 128 characters long, and may contain letters, numbers, '(', ')', '.', '-', '/' and '_'
status code: 400, request id: OMITTED
Build 'amazon-ebs' errored: Error creating AMI: InvalidAMIName.MalformedFix it
- Inspect your
ami_name: look for spaces,+, or other characters outside the allowed set.
- Success check: you spot the offending characters (in the issue,
Centos 7 + Stuff).
- Sanitize it: replace spaces with
-or_, drop+and other symbols. E.g.centos-7-stuff-{{timestamp}}.
- Success check: the name matches
[A-Za-z0-9()./_-]{3,128}.
- Note the prevalidation gap:
packer validatemay not catch this; it fails late, after provisioning. Consider it a known rough edge.
- Success check: you validate names yourself before long builds.
- Re-run
packer build.
- Success check:
Creating the AMIsucceeds.
When to use this
You hit this at the very end of an amazon-ebs build, after provisioning succeeded, when AWS rejects the AMI name.
When NOT to use this
Do not use this for InvalidAMIName.Duplicate (name taken; make it unique) or for build failures earlier in provisioning.
Compatibility
Packer 1.x, amazon-ebs. The character rules come from the EC2 API.
Variants
InvalidAMIName.Malformedfrom timestamps or variables injecting spaces- Names over 128 chars from long prefixes plus timestamps
Root cause
EC2 AMI names allow only a restricted charset. Packer's prevalidation did not reject the bad name, so the build burned full provisioning time before AWS refused it at CreateImage.
Edge cases
{{timestamp}}is safe (digits only). The risk is in your static prefix and variable values.- Slashes are allowed but can confuse console filtering; prefer
-.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.