navigation

Proactive Patching with EC2 Image Builder and Systems Manager

The lab will be set up in ap-southeast-2 (Sydney). Please ensure all operations are performed in this Region.

Authors

  • Tim Robinson, Well-Architected Geo Solutions Architect
  • Stephen Salim, Well-Architected Geo Solutions Architect

Introduction

In the process of building a security strategy, OS Patching is an indispensable activity to ensure that EC2 instances running critical applications always use an operating system with the latest security patches, which will minimize the risk of security vulnerabilities and the attack surface.

The majority of security standards worldwide at least require evidence of the system updating and patching process because this is a daily and mandatory activity. On the other hand, for enterprises with a large number of resources, managers must be careful to avoid potential risks that could arise due to Operational Overhead and ensure that downtime is always minimal.

Therefore, an Automated Patching Solution is highly necessary; besides helping to reduce Operational Overhead, it also creates readiness for future Audits activities.

There are quite a few approaches so that we can automate the OS Patching task through the combination of AWS services.

A typical one among them is utilizing the Blue/Green Deployment method to build a new Amazon Machine Image (AMI) containing the latest patches, then this AMI will be fully ready to be used for EC2 instances running applications. To easily visualize, the following processes will be performed:

  • Automate AMI creation with EC2 Image Builder.
  • Manage and orchestrate tasks with Systems Manager Automation Document.
  • Deploy the new AMI quickly with CloudFormation and ensure minimal downtime with the AutoScalingReplacingUpdate policy.

Goals

  1. Successfully configure EC2 Image Builder with Amazon Linux 2023.
  2. Successfully configure Systems Manager Automation Document.
  3. Understand how to deploy a new AMI to an Auto Scaling Group using a Launch Template without service disruption.

Prerequisites

  1. An AWS account used for TESTING purposes, not for production environments.
  2. AWS CLI v2 installed and configured, if you follow the CLI approach.

Regarding the shell used to run commands. The commands in the lab are provided in two versions, you choose the tab corresponding to your environment:

  • Bash for Linux, macOS, WSL, or AWS CloudShell. CloudShell is the most convenient choice because it already has AWS CLI available and automatically authenticates, requiring no additional configuration.
  • PowerShell for Windows.

If you use Windows PowerShell, please note three commonly error-prone differences:

BashPowerShell
VAR=$(command)$VAR = command
command \ newlineuse backtick `, or write concisely on a single line
head -n 10Select-Object -First 10
curl -scurl.exe -s, because curl is an alias of Invoke-WebRequest

Upon completing this lab, you will be charged for resources that are not covered under the AWS Free Tier. The most significant costs are NAT Gateway and the EBS Snapshot of the AMIs created by Image Builder. Please complete the Resource Cleanup section immediately after finishing.

Estimated Duration

Approximately 90 to 120 minutes, in which the AMI build step of EC2 Image Builder alone takes 20 to 30 minutes.

Contents

The lab will include the following sections:

OrderNameMain Content
1IntroductionContext, goals, and prerequisites
2Base InfrastructureVPC, Subnets, Internet Gateway, NAT Gateway
3Application InfrastructureALB, Launch Template, Auto Scaling Group
4AMI Builder PipelineComponent, Recipe, Infrastructure Configuration, Pipeline
5SSM Build AutomationAutomation Document orchestrating the entire process
6Resource CleanupTear down all created resources