- Newest
- Most votes
- Most comments
Your approach to setting up a maintenance window for patching EC2 instances is on the right track. Let's go through your tasks and provide some guidance:
-
Starting stopped instances: Yes, you can use the AWS-StartEC2Instances document for this task. This document will start the stopped instances in the specified region while ignoring the already running instances. You don't need to worry about accidentally restarting running instances.
-
Checking for updates: This step is typically part of the patching process and doesn't require a separate task. The patching operation will automatically check for available updates.
-
Updating SSM agent and applying patches: You can use the AWS-RunPatchBaseline document for this task. It will update the SSM agent if necessary and apply the appropriate patches based on your patch baseline configuration.
-
Powering off previously stopped instances: Your idea of using uptime to determine which instances to shut down is clever, but there's a simpler and more reliable method. Instead of relying on uptime, you can use instance tags to mark the instances that were initially stopped. Here's a suggested approach:
a. Before starting the instances (in task 1), use a custom automation document or AWS Lambda function to add a tag (e.g., "MaintenanceWindowStarted: True") to all stopped instances. b. After patching, use another custom automation document or Lambda function to stop all instances with the "MaintenanceWindowStarted: True" tag, then remove the tag.
This method ensures you're only stopping the instances that were initially stopped, regardless of their uptime.
To implement this solution cost-effectively:
- Use AWS Systems Manager Maintenance Windows to schedule and manage your tasks.
- Leverage AWS Systems Manager Run Command to execute scripts and commands on your instances.
- Use AWS Lambda functions for custom logic (like tagging instances) if needed.
- Utilize resource groups to target your instances efficiently.
This approach minimizes the need for additional resources and leverages AWS's native capabilities, keeping costs down while providing a robust patching solution.
Sources
Stop and start Amazon EC2 instances - Amazon Elastic Compute Cloud
Setting up Maintenance Windows - AWS Systems Manager
Step 1: Create the maintenance window using the AWS CLI - AWS Systems Manager
Hi,
The full workflow of what you want to achieve is detailled here: https://medium.com/globant/patching-of-windows-and-linux-ec2-instances-using-aws-ssm-b409784a5bd7
Please, follow this article to implement your own case. In particular, focus on the section(s) about the maintenance window: you should leverage it to achieve what you want.
Best,
Didier
Relevant content
asked 4 years ago
asked 2 years ago
