SkillSprout
Chapter 3 · Lesson 4
Intermediate
6 min read

AMIs, EC2 Image Builder and Service Catalog

Overview

An Amazon Machine Image (AMI) is a template for launching EC2 instances: an OS, software and configuration snapshot. A golden AMI is a hardened, pre-patched image your organisation approves, so every server starts identical instead of being configured by hand after launch.

EC2 Image Builder automates the creation, testing, distribution and patching of AMIs (and container images) through a pipeline. AWS Service Catalog lets administrators publish approved infrastructure products (CloudFormation templates) that end users can launch without needing broad permissions.

Think of a franchise: head office designs the approved kitchen layout (golden image, catalog product) and each branch simply opens one, guaranteeing consistency and compliance.

Key Concepts

  • AMIs are Region-specific; copy them to other Regions. They are backed by EBS snapshots and can be shared with accounts/organisations or made public.
  • Encrypted AMIs can be shared only if the KMS key is also shared (customer-managed key); AWS-managed keys cannot be shared.
  • EC2 Image Builder: image recipe (base image + components) + infrastructure configuration + distribution settings + schedule; includes test components and vulnerability scanning with Inspector.
  • Launch templates (versioned) define how instances launch; launch configurations are deprecated.
  • Service Catalog: portfolios, products (CloudFormation/Terraform), constraints (launch role, template, notification), tags and sharing across accounts.
  • Use SSM Parameter Store to publish the latest golden AMI ID that templates and ASGs resolve.
  • Elastic Beanstalk handles app deployment (rolling, immutable, blue/green, all-at-once); OpsWorks (Chef/Puppet) reached end of life in 2024 – prefer SSM and CloudFormation.
  • AMI deprecation and deregistration with snapshots deletion keeps cost under control.

Detailed Notes

Building and sharing AMIs manually

bash
aws ec2 create-image --instance-id i-0abc --name "web-2025-03-01" --no-reboot
aws ec2 copy-image --source-image-id ami-0123 --source-region us-east-1 --region eu-west-1 \
  --name web-2025-03-01 --encrypted --kms-key-id alias/ami-eu
aws ec2 modify-image-attribute --image-id ami-0123 \
  --launch-permission "Add=[{UserId=444455556666}]"
aws ec2 deregister-image --image-id ami-0123

--no-reboot risks filesystem inconsistency; stop the instance or quiesce for critical data. Deregistering an AMI does not delete its snapshots – delete them separately.

Sharing encrypted AMIs

ScenarioWorks?
Unencrypted AMI to another accountYes
Encrypted with customer-managed key, key sharedYes
Encrypted with AWS-managed aws/ebs keyNo – copy and re-encrypt with a CMK first

EC2 Image Builder pipeline

ComponentPurpose
Image recipeBase AMI + ordered build/test components (e.g. update-linux, CIS hardening, install agent)
Infrastructure configurationInstance type, subnet, SG, IAM role, SNS topic for build
Distribution settingsRegions, accounts, AMI name, KMS keys, launch permissions
Pipeline scheduleCron or when a new parent image is available
yaml
Resources:
  Recipe:
    Type: AWS::ImageBuilder::ImageRecipe
    Properties:
      Name: web-golden
      Version: 1.0.0
      ParentImage: !Sub arn:aws:imagebuilder:${AWS::Region}:aws:image/amazon-linux-2023-x86/x.x.x
      Components:
        - ComponentArn: !Sub arn:aws:imagebuilder:${AWS::Region}:aws:component/update-linux/x.x.x
        - ComponentArn: !Sub arn:aws:imagebuilder:${AWS::Region}:aws:component/amazon-cloudwatch-agent-linux/x.x.x
  Pipeline:
    Type: AWS::ImageBuilder::ImagePipeline
    Properties:
      Name: web-golden-pipeline
      ImageRecipeArn: !Ref Recipe
      InfrastructureConfigurationArn: !Ref InfraConfig
      Schedule: { ScheduleExpression: "cron(0 4 ? * sun *)" }

After each successful build, an EventBridge rule or SNS notification can update the SSM parameter holding the latest AMI and trigger an ASG instance refresh.

Service Catalog

ItemDescription
PortfolioCollection of products shared with IAM principals/accounts/OUs
ProductA CloudFormation template (versions)
ConstraintLaunch (IAM role used), notification, template parameter limits, tag update
Provisioned productThe running stack launched by an end user

Users need only Service Catalog permissions; the launch constraint role carries the privileges to create resources. This enforces governance without giving developers broad IAM rights.

Deployment options on Elastic Beanstalk

PolicyDowntimeNotes
All at onceYesFastest
RollingNo (reduced capacity)Batches
Rolling with additional batchNoKeeps full capacity
ImmutableNoNew ASG, easy rollback
Blue/greenNoSwap CNAMEs

Troubleshooting

ProblemCause
Cannot launch shared AMILaunch permission, KMS key not shared, wrong Region
Image Builder build failsInstance has no outbound access/SSM role; failing component; check pipeline logs in S3/CloudWatch
Users cannot launch a productLaunch constraint role missing permissions, or portfolio not shared with the principal
TaskHow
Copy AMI across Regionsaws ec2 copy-image; can re-encrypt with a destination KMS key
Share AMIModify launch permissions to accounts or organizations; encrypted AMIs also need the KMS key shared
Deprecate / deregisterSet deprecation time; deregister then delete snapshots to stop cost
Automate retentionAmazon Data Lifecycle Manager policies for snapshots and AMIs
Image BuilderRecipe (base image + components), infrastructure config, distribution settings, schedule
Service CatalogPortfolios of approved CloudFormation products with launch constraints and TagOptions
bash
aws ec2 copy-image --source-image-id ami-0abc --source-region us-east-1 --region eu-west-1 --name golden-eu --encrypted
aws ec2 modify-image-attribute --image-id ami-0abc --launch-permission "Add=[{UserId=444455556666}]"
aws ec2 deregister-image --image-id ami-0old
aws imagebuilder start-image-pipeline-execution --image-pipeline-arn arn:aws:imagebuilder:us-east-1:111122223333:image-pipeline/golden

Service Catalog lets users launch only approved products through a launch role, so they need no direct CloudFormation or service permissions. AWS OpsWorks (Chef/Puppet) has reached end of life, so modern answers use Systems Manager, CloudFormation or containers instead. Bake slow-changing software into AMIs, and use user data or SSM for fast-changing configuration.

Real World Example

Scenario – weekly patched golden image. Security requires every EC2 instance to run an image patched within 7 days. The team builds an Image Builder pipeline that starts from the latest Amazon Linux 2023, applies hardening and the CloudWatch agent, runs a test component, scans with Inspector and distributes encrypted AMIs to three Regions and accounts.

On success an EventBridge rule updates an SSM parameter /golden/web/latest and starts an instance refresh on the web ASGs. Teams request new environments via Service Catalog, whose templates always reference the parameter, so users get compliant images without needing EC2 permissions.

Architecture Diagram

Golden image pipeline
Architecture
AWS Cloud
Image Builderrecipe + tests
Golden AMIencrypted
SSM parameterlatest AMI
ASG refresh
Service Catalog
  1. 1A scheduled pipeline builds from the latest parent image and applies components.
  2. 2Tests and vulnerability scans must pass before distribution.
  3. 3The new AMI is copied to target Regions and accounts, and its ID is stored in Parameter Store.
  4. 4Auto Scaling groups and Service Catalog products consume the new image.

Best Practices

  • ✓Build golden AMIs through a pipeline, not by hand, and include tests and scans.
  • ✓Publish the latest AMI ID in Parameter Store and reference it from launch templates/CloudFormation.
  • ✓Use customer-managed KMS keys for AMIs you need to share.
  • ✓Deprecate and clean up old AMIs and their snapshots.
  • ✓Use Service Catalog with launch constraints to give self-service within guardrails.

Common Interview Questions

Exam Tips

SOA-C03 focus

  • Automated, tested, patched golden images -> EC2 Image Builder.
  • Approved self-service products with guardrails -> Service Catalog.
  • AMIs are Region-specific: use copy-image for DR Regions.
  • OpsWorks is end-of-life; modern answers use Systems Manager and CloudFormation.

Chapter quiz

Deployment, Provisioning and Automation · 10 questions

  1. 1.Before updating a production CloudFormation stack, an engineer wants to know whether any resources will be replaced. What should they use?

  2. 2.Operations wants to open shell sessions to private EC2 instances without bastion hosts, SSH keys or inbound security group rules, and keep an audit trail. What should they use?

  3. 3.Which approach installs critical security patches on a group of instances every Sunday night, staggered by environment, with compliance reporting?

  4. 4.A CloudFormation stack that creates an EC2 instance stays in CREATE_IN_PROGRESS and eventually fails with a timeout, although the instance is running. What is the most likely cause?

  5. 5.A team needs to share an encrypted AMI with a partner account. The AMI is currently encrypted with the AWS managed aws/ebs key. What is required?

  6. 6.A CloudFormation stack update is stuck in UPDATE_ROLLBACK_FAILED because a resource was manually deleted. What is the best next step?

  7. 7.Managed instances in private subnets with no internet access do not appear in Systems Manager. The instance profile is correct. What is missing?

  8. 8.Patches must be applied to production servers only on Saturdays between 01:00 and 04:00, with at most 10 percent of instances at a time. Which design fits?

  9. 9.The security team wants developers to launch only approved CloudFormation stacks without holding permissions for the underlying services. Which service enables this?

  10. 10.A golden AMI must be rebuilt every week with the latest OS patches, tested and copied to three Regions with no custom servers to manage. What should be used?

0 of 10 answered

Finished this lesson?

0 of 46 lessons done · 0% of the course