Packer – AWS Windows 2016 SysPrep returns exit code 1

amazon-web-servicespackersysprepwindows-server-2016

When attempting to SysPrep an AWS Windows Server 2016 instance using Packer the following error is thrown:

Build 'amazon-ebs' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

I'm calling the SysprepInstance.ps1 script as specified on http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2launch.html#ec2launch-sysprep.

Best Answer

Castrohenge's answer set me on the right path, but I preferred to pass the '-NoShutdown' switch to SysprepInstance.ps1 to accomplish the same goal.

C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown

Also keep in mind that features requiring restart can lock up sysprep and will fail to report back to packer. To solve that I simply use the 'restart' provisioner in packer before sysprep.