This guide provides a walkthrough for setting up the necessary configuration for AWS Systems Manager Patch Manager to automatically scan and/or apply patches to EC2 instances in an AWS environment. The following is included:
This configuration requires EC2 instances to be configured to use AWS Systems Manager. See below for full details on prerequisites.
AWS Systems Manager Maintenance Windows let you define a schedule for when to perform potentially disruptive actions on your instances such as patching an operating system, updating drivers, or installing software or patches.
The main configuratin items for a Maintenance Window:
The main items to configure for a Systems Manager Maintenance Window are:
Specify the Targets for the Maintenance Window. The targets are specified using Amazon EC2 tags that are assigned to the instances.
Enter Tag Key/Value pairs to specify which EC2 instances the Maintenance Window performs actions on. Multiple tag values are supported for the same tag key
Default is Tag Key:Automatic Patches, Tag Value:True
Systems Manager provides a predefined document AWS-RunPatchBaseline to trigger the patch operations. It can be configured to Scan only (and provide a report in the Systems Manager console), or Install missing patches.
Instance concurrency sets how many instances receive the command at the same time.
Enable the Write command output to an Amazon S3 bucket feature to save the patch operations output to a file on S3. Type the bucket and prefix (folder) names in the boxes.
SNS notifications can be enabled to send notifications about the status of the command execution. You can specify an existing SNS topic or create a new one.
Notifications can be set to send on a certain type of events, as well as per Invocation or per Command.
A patch baseline defines which patches are approved for installation on your instances. You can specify approved or rejected patches one by one. You can also create auto-approval rules to specify that certain types of updates (for example, critical updates) should be automatically approved.
Patch Manager provides predefined patch baselines for each of the operating systems supported by Patch Manager. You can use these baselines as they are currently configured (you can't customize them) or you can create your own patch baselines if you want greater control over which patches are approved or rejected for your environment.
The following table provides a quick description for each predefined baseline and its patch rules
Custom Patch Baselines allow custom rules for selecting which patches are applied to instances and operating systems. Patches to be installed are defined based on rules (up to 10), which include the following options:
Patch groups are used to associate instances with a specific patch baseline. Patch groups help ensure that you are deploying the appropriate patches, based on the associated patch baseline rules, to the correct set of instances.
Patch groups are Tags assigned to Instances, but must have the key Patch Group. The values can be anything. (Default configuration has the value custom-patch-group)
Optionally, enable Set as Default Patch Baseline to make the new Patch Baseline the default one for all instances. It is recommended to review the patch rules carefully before selecting this option. (A CloudFormation custom resource is included to enable this option)
AWSTemplateFormatVersion: '2010-09-09'
Description: ''
Resources:
MaintenanceWindow:
Type: 'AWS::SSM::MaintenanceWindow'
Properties:
Name: Patch-Manager-Maintenance-Window
Description: SSM Maintenance Window to automate AWS Patch Manager tasks
Duration: '4'
Cutoff: '1'
Schedule: cron(00 00 ? * SAT *)
AllowUnassociatedTargets: false
MaintenanceWindowTarget:
Type: 'AWS::SSM::MaintenanceWindowTarget'
Properties:
Name: Target-For-Patch-Manager-Maintenance-Window
Description: 'Defines the EC2 Instance Targest for Maintenance Window: Patch-Manager-Maintenance-Window'
ResourceType: INSTANCE
WindowId:
Ref: MaintenanceWindow
Targets:
- Key: 'tag:Automatic Patches'
Values:
- 'True'
MaintenanceWindowTask:
Type: 'AWS::SSM::MaintenanceWindowTask'
Properties:
Name: Task-For-Patch-Manager-Maintenance-Window
Description: 'Defines the Task for Maintenance Window: Patch-Manager-Maintenance-Window'
ServiceRoleArn:
'Fn::GetAtt':
- MaintWindowIamRole
- Arn
Priority: 1
MaxErrors: 1
MaxConcurrency: 2
Targets:
- Key: WindowTargetIds
Values:
- Ref: MaintenanceWindowTarget
TaskType: RUN_COMMAND
WindowId:
Ref: MaintenanceWindow
TaskArn: AWS-RunPatchBaseline
TaskInvocationParameters:
MaintenanceWindowRunCommandParameters:
Parameters:
Operation:
- Install
ServiceRoleArn:
'Fn::GetAtt':
- MaintWindowIamRole
- Arn
MaintWindowIamRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: MaintWindowIamRoleFKS
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- ssm.amazonaws.com
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonSSMMaintenanceWindowRole'
IamInlinePolicy:
Type: 'AWS::IAM::Policy'
Properties:
PolicyName: taskRolePermissions
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'iam:PassRole'
Resource:
'Fn::GetAtt':
- MaintWindowIamRole
- Arn
Roles:
- Ref: MaintWindowIamRole
Parameters: {}
Metadata: {}
Conditions: {}