Skip to content

Instantly share code, notes, and snippets.

@timsutton
Last active May 1, 2025 14:33
Show Gist options
  • Save timsutton/833d58ef264825dc647c5b30da3eae14 to your computer and use it in GitHub Desktop.
Save timsutton/833d58ef264825dc647c5b30da3eae14 to your computer and use it in GitHub Desktop.
Building EC2 Mac AMIs with Packer

Mitigate issues with network interface configuration in EC2 Mac instances

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment