Using Patch Manager to Auto-Patch EC2 Instances
Following the Systems Manager Session Manager setup, this guide covers Patch Manager to automatically scan and install OS patches on EC2 instances on a schedule.
Once you have Session Manager set up and SSM Agent running,
the next step is to automate patch management itself.
This is where Patch Manager comes in.
What is Patch Manager?
Patch Manager is a feature within AWS Systems Manager
that lets you centrally manage OS and application patches across multiple EC2 instances.
Core capabilities:
- Patch scanning: detect which patches are available
- Patch installation: apply patches on schedule or manually
- Compliance reporting: aggregate patch status across fleet
- Exclusion rules: skip certain patches if needed
Compared to manual updates or homegrown cron jobs,
Patch Manager offers:
- Centralized policy management
- Audit trails and compliance reports
- Flexible scheduling with maintenance windows
- Automatic rollback on failure
Prerequisites
Similar to Session Manager, you need:
- EC2 already configured for Session Manager (IAM Role, Agent running)
- EC2 can reach SSM endpoints (already set up)
- IAM Role has Patch Manager permissions
Configure IAM Policy
If you already have AmazonSSMManagedInstanceCore attached,
Patch Manager permissions are included.
For finer control, you can add this custom policy:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeDocument",
"ssm:GetDocument",
"ssm:DescribeDocumentParameters"
],
"Resource": "arn:aws:ssm:*:*:document/AWS-RunPatchBaseline"
},
{
"Effect": "Allow",
"Action": [
"ssm:GetAutomationExecution",
"ssm:StartAutomationExecution",
"ssm:GetCommandInvocation",
"ssm:ListCommandInvocations",
"ssm:ListCommands"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "arn:aws:sns:*:*:aws-patch-manager-*"
}
]
}
Patch Manager typically doesn’t require extra S3 or service permissions
unless you have custom patch sources.
How Patch Manager Works
There are two operational modes:
- Scan Only: check what patches are available, don’t install
- Scan and Install: scan and apply patches automatically
In practice, start with Scan Only for a few weeks,
then switch to Scan and Install once you’re confident.
Setting Up Patch Scheduling
Step 1: Create a Patch Baseline
In AWS Console, go to Systems Manager > Patch Manager > Patch Baselines.
Create a new baseline:
- Name: e.g.
linux-standard - OS: choose Linux or Windows
- Approval rules:
- Enable auto-approval for patches matching certain classifications
- Common choices:
Security,Bugfix,Enhancement - Can also set approval delay (e.g. approve 7 days after release)
For patches you want to skip,
add them to Patch exceptions.
Step 2: Create a Maintenance Window
In Systems Manager, go to Maintenance Windows.
Create a new maintenance window:
- Name: e.g.
weekly-patch-sunday - Schedule: Cron format, e.g. every Sunday at 2 AM
1
cron(0 2 ? * SUN *)
- Duration: e.g. 2 hours (buffer time)
- Timezone: your ops timezone
Step 3: Create a Patch Task
Add a task within that maintenance window:
- Task type:
Run command - Document:
AWS-RunPatchBaseline - Service role: your Patch Manager role
- Targets: select EC2 instances
- Use tags (e.g.
Environment: Production) - Or specify Instance IDs directly
- Use tags (e.g.
- Parameters:
- Operation:
Install(scan + install) orScan(scan only) - Baseline Override: if multiple baselines exist, specify which one
- Operation:
Step 4: Wait for Scheduled Execution
Patch Manager will run at your specified maintenance window.
Check compliance in Patch Manager > Compliance.
Each EC2 will show one of:
- Compliant: all patches installed
- Non-compliant: some patches pending
- Failed: execution failed
Common Practices
1. Start with Scan Only
Don’t jump straight to Install.
Run Scan for a few weeks to validate patch lists
before switching to Install.
2. Separate by Environment
Create different baselines for Dev, Staging, Prod.
Production can use conservative approval rules (delay 2-4 weeks),
while Dev is more aggressive.
3. Use Patch Groups
Tag EC2s with Patch Group to apply different strategies.
Reference these groups in your baselines.
4. Enable Notifications
Integrate with SNS or EventBridge
to get patch completion notifications and audit logs.
Essentially, EventBridge captures state changes from EC2 after Scan or Install,
then sends events downstream.
A simple EventBridge + SNS setup can deliver basic notifications.
For more detailed content—such as patch lists, failure reasons, and other specifics—
add a Lambda function to process and enrich the notification before sending via SNS.
Troubleshooting
1) Maintenance Window passed but patches didn’t run
Check:
- EC2 IAM Role has Patch permissions
- EC2 is Online (verify with
aws ssm describe-instance-information) - Maintenance Window targets include this EC2
2) Patch execution failed
Common causes:
- Patch install requires reboot but auto-reboot is off
- Patch is incompatible with the system
- Insufficient disk space
Review the detailed logs in Compliance.
3) System degrades after patching
Test patches in Staging first
to catch compatibility issues before Production.
4) Need to skip one patch run
Temporarily disable the Maintenance Window
or remove the EC2 from targets.
Summary
Patch Manager’s core value is:
no more manual SSH into each server,
unified scheduling, reporting, and auditing.
Recommended rollout:
- Use Scan to understand current state
- Test Install in non-critical environments
- Set up tiered policies (Dev / Staging / Prod)
- Monitor Compliance reports continuously
This establishes a robust automated patch governance process.
References
- AWS Patch Manager: https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-manager.html
- AWS-RunPatchBaseline Document: https://docs.aws.amazon.com/systems-manager/latest/userguide/documents-ssm-docs-run-command.html
- Patch Baselines: https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-baselines.html
- Maintenance Windows: https://docs.aws.amazon.com/systems-manager/latest/userguide/maintenance-windows.html