Patch Management and Golden Image Pipelines
Overview
Unpatched software is one of the most common causes of breaches. AWS Systems Manager Patch Manager automates scanning and installing OS and application patches on EC2 instances, on-premises servers and edge devices, according to patch baselines you define, during maintenance windows you control.
Patching is like servicing a fleet of delivery vans. You do not recall every van at once; you service a few at a time overnight, check each one afterwards and keep a log of which vans are up to date. Alternatively, you can swap vans for new pre-serviced ones, which is the immutable approach using golden images.
DOP-C02 expects you to choose between patch in place (Patch Manager) and replace (Image Builder AMIs with instance refresh), to know the building blocks (baselines, patch groups, maintenance windows, compliance reporting) and to apply them across accounts and Regions.
Key Concepts
- A patch baseline defines approved patches (classification, severity, auto-approval delay, explicit approve/reject lists); AWS provides default baselines per OS.
- Patch Manager runs the AWS-RunPatchBaseline document with Operation Scan or Install; installs may reboot per RebootOption.
- Patch groups (tag
Patch Group) associate instances with a baseline; maintenance windows schedule Run Command tasks with concurrency and error thresholds. - Patch policies in Quick Setup apply patching configuration across an organisation, OUs and Regions centrally.
- Compliance reports show missing patches per instance; data syncs to S3 and can be queried with Athena or sent to Security Hub.
- Inspector finds vulnerable packages; Patch Manager fixes them; Config/Systems Manager Inventory shows installed software.
- EC2 Image Builder builds, tests, hardens and distributes golden AMIs/container images through pipelines with schedules, and can trigger on new base image releases.
- The immutable pattern replaces instances with a new AMI via instance refresh, avoiding drift and long-running in-place changes.
Detailed Notes
Patch in place vs replace
| Aspect | Patch Manager (in place) | Golden AMI (replace) |
|---|---|---|
| Fits | Long-lived servers, on-premises, pets | Stateless ASG fleets, containers |
| Drift risk | Higher | Low |
| Rollback | Hard (restore snapshot) | Easy (previous AMI) |
| Speed to apply | Gradual in a window | Pipeline plus refresh |
| Testing | In patch ring order | Tested before release |
Patch baseline
aws ssm create-patch-baseline --name prod-linux --operating-system AMAZON_LINUX_2023 \
--approval-rules 'PatchRules=[{PatchFilterGroup={PatchFilters=[{Key=CLASSIFICATION,Values=[Security]},{Key=SEVERITY,Values=[Critical,Important]}]},ApproveAfterDays=3,ComplianceLevel=CRITICAL}]'
aws ssm register-patch-baseline-for-patch-group --baseline-id pb-0123456789 --patch-group prod-web
ApproveAfterDays delays approval to let a patch mature; ApprovalRules with cutoff date for Windows lets you pin to a date. Tag instances with Patch Group=prod-web so they use that baseline.
Maintenance window
aws ssm create-maintenance-window --name prod-web-sunday --schedule "cron(0 2 ? * SUN *)" \
--duration 3 --cutoff 1 --allow-unassociated-targets
aws ssm register-target-with-maintenance-window --window-id mw-0abc --resource-type INSTANCE \
--targets Key=tag:Patch\ Group,Values=prod-web
aws ssm register-task-with-maintenance-window --window-id mw-0abc --task-type RUN_COMMAND \
--task-arn AWS-RunPatchBaseline --targets Key=WindowTargetIds,Values=$TARGET_ID \
--task-invocation-parameters 'RunCommand={Parameters={Operation=[Install]}}' \
--max-concurrency 20% --max-errors 5% --service-role-arn $ROLE
Concurrency and error thresholds let a bad patch stop after a few failures. For fleets behind a load balancer, use rolling windows by AZ or use Automation with ASG instance refresh.
Patch rings
- Ring 0: dev and canary instances patched immediately after release.
- Ring 1: test/staging after a few days of clean results.
- Ring 2: production in small waves through maintenance windows, monitoring alarms between waves.
Quick Setup patch policy
A patch policy at the organisation level defines baselines, scan/install schedules and targets (tags, all instances) with Region and OU scope, avoiding per-account configuration. Findings flow to a central compliance view.
Golden image pipeline with Image Builder
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: !Ref HardeningComponent
- ComponentArn: !Ref AppTestComponent
Pipeline:
Type: AWS::ImageBuilder::ImagePipeline
Properties:
Name: web-golden-weekly
ImageRecipeArn: !Ref Recipe
InfrastructureConfigurationArn: !Ref Infra
DistributionConfigurationArn: !Ref Distribution
Schedule: { ScheduleExpression: "cron(0 4 ? * SUN *)", PipelineExecutionStartCondition: EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE }
Stages: build (update + harden), test (run test components, Inspector scan), distribute (copy to Regions/accounts, share AMI, write ID to an SSM parameter). An EventBridge rule on image creation then updates the launch template and starts an instance refresh.
Parameter-based AMI selection
Parameters:
LatestAmi:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /golden/web/latest
Stack updates pick up the newest image, while pinned parameter versions allow controlled promotion between environments.
Compliance, reporting and enforcement
- Compliance: Systems Manager Compliance dashboard; Resource Data Sync exports to S3 for Athena/QuickSight.
- Config rule
ec2-managedinstance-patch-compliance-status-checkflags non-compliant instances and can trigger remediation (run Install). - Inspector prioritises which patches matter; Security Hub aggregates results.
- Use SCP or Config to block launching AMIs not owned or approved (for example
ec2:ImageOwneror Allowed AMIs setting).
Special cases
Windows patching uses WSUS-like KB approval via baselines; Linux kernel patches need reboot or live patching (Amazon Linux). Containers should be rebuilt from updated base images rather than patched live; ECR enhanced scanning alerts on new CVEs. For Lambda, update runtimes and layers and redeploy.
Patch Manager configuration
aws ssm create-patch-baseline --name prod-linux --operating-system AMAZON_LINUX_2023 \
--approval-rules "PatchRules=[{PatchFilterGroup={PatchFilters=[{Key=CLASSIFICATION,Values=[Security]}]},ApproveAfterDays=3,ComplianceLevel=CRITICAL}]"
aws ssm register-task-with-maintenance-window --window-id mw-0123 --task-type RUN_COMMAND \
--task-arn AWS-RunPatchBaseline --targets Key=tag:PatchGroup,Values=prod \
--task-invocation-parameters "RunCommand={Parameters={Operation=[Install]}}" --max-concurrency 10% --max-errors 5%
- Use patch groups (tag
Patch Group) to map instances to baselines, and Scan versus Install operations to separate reporting from change. - Patch policies (Quick Setup) apply schedules and baselines organisation-wide, with compliance in Explorer and an S3 report.
- For immutable fleets, build patched AMIs with Image Builder and roll out with instance refresh; patch live instances only when you must.
- Use Maintenance Windows with concurrency and error limits so a bad patch stops the rollout early, and verify with health checks after reboot.
Real World Example
Scenario: a company runs 800 EC2 instances across 40 accounts. Stateless web tiers use a weekly Image Builder pipeline (update, CIS hardening, Inspector scan) with the new AMI ID written to an SSM parameter; an EventBridge rule starts an instance refresh at 20% checkpoints with alarm rollback.
Stateful database hosts and on-premises servers are patched with a Quick Setup patch policy: scan daily, install on Sunday windows with 10% concurrency and 2% error tolerance. A central compliance dashboard shows patch status for auditors.
Architecture Diagram
Replace stateless fleets with new images; patch long-lived servers in controlled waves.
- 1A scheduled pipeline builds, hardens, tests and scans a new image.
- 2The new AMI ID is distributed and written to an SSM parameter.
- 3An instance refresh replaces stateless instances gradually with alarm rollback.
- 4Long-lived servers are scanned and patched in maintenance windows with rate control.
- 5Compliance data is aggregated for audit and remediation.
Best Practices
- ✓Prefer immutable AMIs for stateless fleets; patch in place only for long-lived systems.
- ✓Use patch rings and low max-concurrency/max-errors to limit blast radius.
- ✓Manage patching centrally with Quick Setup patch policies and compliance sync.
- ✓Test images with Inspector and automated test components before distribution.
- ✓Reference AMIs through SSM parameters and rebuild regularly, not just on incidents.
Common Interview Questions
Exam Tips
DOP-C02 focus
- "Patch on a schedule with controlled concurrency" = Patch Manager + maintenance window.
- "Standardised, hardened, tested AMIs" = EC2 Image Builder.
- "Apply patching configuration across the organisation" = Quick Setup patch policy.
- Tag
Patch Groupassociates instances with a patch baseline.
Finished this lesson?
0 of 44 lessons done · 0% of the course

