This blog was originally written and published by Trek10, which is now part of Caylent.
We live in a world where we need to remember that OS or base packages on the instance need to be updated because security is critically important.
When in our ENV, there are a lot of instances. Sometimes it’s easy to make a mistake or we can forget to update one of the instances.
With AWS SSM we can schedule automatic updates for our EC2 instances.
AWS Systems Manager Agent (SSM Agent) is Amazon software that can be installed and configured on an Amazon EC2 instance, an on-premises server, or a virtual machine (VM). SSM Agent makes it possible for Systems Manager to update, manage, and configure these resources. The agent processes requests from the Systems Manager service in the AWS Cloud, and then runs them as specified in the request. SSM Agent then sends status and execution information back to the Systems Manager service by using the Amazon Message Delivery Service (service prefix: ec2messages).
For this article, I will create a small ENV. For better usage of SSM, we need to add correct tags to EC2 instances and install SSM agent on these instances.
Our update plan:
- Before updating instances, AMI Image will be automatically created as a backup solution.
- Staging instances will be patched on Saturday at 06:00 AM UTC
- Install only Critical and Important updates on the instances
Getting Set Up
In Staging ENV there will be two EC2 instances using Ubuntu 14.04 OS (called stage web01 and stage web02).
Tags
If we have a large environment, tags are helpful. For our article, we will attach 3 tags to instances:
- env:staging
- os:ubuntu14
- Patch Group:ubuntu_staging
From these tags we know that instance is from environment staging using OS ubuntu 14 and this instance is part of the Patch Group ubuntu_staging. This is important later on.
AWS SSM Agent
SSM Agent is installed by default on the following AMIs:
- Windows Server 2003-2012 R2 AMIs published in November 2016 or later
- Windows Server 2016 and 2019
- Amazon Linux
- Amazon Linux 2
- Ubuntu Server 16.04
- Ubuntu Server 18.04
Our instances are using The Ubuntu 14.04 which doesn’t have the SSM agent installed by default. We need to manually install SSM agent. You can read the AWS docs on installing the SSM agent.
AWS IAM Roles
By default, AWS Systems Manager doesn’t have permission to perform actions on your instances. You must grant access by using an AWS Identity and Access Management (IAM) instance profile. An instance profile is a container that passes IAM role information to an Amazon Elastic Compute Cloud (Amazon EC2) instance at launch. You can create an instance profile for Systems Manager by attaching one or more IAM policies that define the necessary permissions to a new role or to a role you have already created.
For following along in this article, you will need two IAM Roles.
The first IAM Role will be called role-for-ssm. This role will be attached to our two instances.
Go to the AWS Console -> IAM -> Roles and hit the “Create role” button
Create a role called role-for-ssm and attach the AWS manager policy called: AmazonEC2RoleforSSM