One issue that EC2 Mac customers often run into with custom AMI creation, is that launching new instances with the AMI can fail reachability health checks. This can be especially common if multiple "layers" of AMI builds are done.
See the "Network interfaces cached in AMIs" slide near the end of this re:Invent 2024 presentation.
Make sure you do these two steps (mentioned on that slide) at the end of the build:
sudo rm -f /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
sudo shutdown -h now
For the shutdown
command, it will prevent future SSH/SCP connections from Packer, and also initiates a shutdown. So, Packer will need a couple additional settings to be configured during the script provisioner block:
Finally, you should also add some time delay before Packer completes the build, so that the Mac host has time to completely shut down, quiesce the system and filesystems, etc. You can do this by adding a sleep <seconds>
in a local shell provisioner. Expect that the shutdown will be somewhat slower than on a "normal" Mac due to the slower EBS boot volume.