Opscraft
Image building with Packer · Lesson 5 of 5 · 3 min read

Interview questions and model answers

"How do you patch 300 EC2 instances?"

Ideally we don't patch them in place. A scheduled pipeline builds a new golden AMI with Packer from the latest base image, runs tests and an Inspector scan, publishes it to an SSM parameter, and each Auto Scaling group gets a new launch template version followed by an instance refresh in batches with health checks and rollback. For the few long-lived servers that can't be replaced, I'd use Systems Manager Patch Manager with maintenance windows and patch baselines.

"Bake or fry?"

Bake what is slow, stable and the same everywhere — OS updates, agents, runtimes and hardening — so instances boot fast and reliably during scale-out. Fry what is environment-specific or secret at boot via user data — which cluster to join, configuration, secrets fetched with the instance role. Baking everything means rebuilding images for every config change; frying everything makes boots slow and fragile.

"Walk me through what Packer does when building an AMI."

It finds the source AMI from the filter, creates a temporary key pair and security group, launches a temporary instance, connects over SSH or Session Manager, runs the provisioners, stops the instance, creates the AMI and snapshots, then terminates the instance and deletes the temporary resources. If a step fails it cleans up and exits non-zero.

"What do you clean up before creating an image?"

Anything that should be unique per instance or that leaks information: SSH host keys, the machine ID, cloud-init state so it runs again, shell history, logs, temporary files and package caches. And above all, no secrets in the image, since AMIs get copied and shared; secrets are fetched at boot.

"How do other accounts use your AMIs?"

The pipeline copies the AMI to the needed regions and shares it with the workload accounts or the whole organisation through launch permissions. If snapshots are encrypted with a customer-managed key, the key policy must allow those accounts to use it. Consumers look up the current AMI from an SSM parameter or the HCP Packer registry rather than hard-coding IDs.

"How do you roll a new AMI out to EKS nodes?"

With managed node groups, update the launch template or AMI version and let the update cordon, drain and replace nodes while respecting PodDisruptionBudgets. With Karpenter, change the AMI selection in the EC2NodeClass; Karpenter detects drift and replaces nodes gradually within the NodePool's disruption budgets. Either way, roll out per environment and keep the previous AMI for rollback.

"Packer or EC2 Image Builder?"

Image Builder is fully managed and AWS-native, with pipelines, tests and distribution as AWS resources, which suits AWS-only teams who don't want to run build infrastructure. Packer is multi-cloud, templates live in Git next to Terraform, it runs in any CI system and is easy to test locally. I'd choose based on whether we need more than AWS and where the team already works.