Using Systems Manager To Automate Operational Tasks Across AWS Resources
Olumoko Moses
Posted on March 14, 2023
If you’re an AWS administrator, you know that managing a big infrastructure with hundreds or thousands of instances can be a time-consuming and error-prone process. But what if you could automate these tasks and streamline your operations? Amazon Systems Manager (SSM) provides a powerful solution, allowing you to automate a wide range of IT operations tasks. In this article, we’ll focus on how to use Amazon Systems Manager (Run Command) to automate tasks across multiple ec2 instances.
What Is Cloud Service?
A Cloud Service is any system that provides on-demand availability of computer system resources, e.g; data storage and computing power, without direct active management by the user.
Cloud is like an extra hard drive/computer that is somewhere away from you, which you can access anytime just by connecting to the Internet.
What Is AWS?
AWS is an on-demand online platform by AMAZON that provides secured, scalable, cost-effective cloud services.
What Is EC2 & EC2 Instance?
EC2 is an on-demand computing service on the AWS cloud platform that allows users to rent virtual computers on which to run their computer applications.
EC2 Instance is a virtual server in (EC2) *for running applications on the Amazon Web Services *(AWS) infrastructure.
So, EC2 is a service provided by AWS, while an EC2 instance is a virtual machine launched using this service.
What Is a Systems Manager?
AWS Systems Manager gives you visibility and control of your infrastructure on AWS. Systems Manager provides a unified user interface so you can view operational data from multiple AWS services and enables you to automate operational tasks including patching, configuration management, and deployment across your AWS resources which reduced the time and effort required to manage your infrastructure, while also reducing the risk of errors.
Systems Manager Prerequisites for EC2 instances:
To enable the AWS Systems Manager to manage your Amazon Elastic Compute Cloud (Amazon EC2) instances, we need to check the prerequisites first. Let’s go through the important points listed below:
Configure the required AWS Identity and Access Management (IAM) roles with the AmazonEC2RoleforSSM policy attached.
Verify that your instances run a supported operating system like Amazon Linux.
For Amazon EC2 instances, you can create an IAM instance profile and attach it to your machines.
Install or verify the installation of the SSM Agent on each of your Managed instances.
*Note: *AWS Systems Manager Agent (SSM Agent) is preinstalled on some Amazon Machine Images (AMIs) provided by AWS.
For example, when you launch an Amazon Elastic Compute Cloud (Amazon EC2) instance created from an AMI with one of the following operating systems, you’ll likely find that the SSM Agent is already installed:
Amazon Linux Base AMIs dated 2017.09 and later
Amazon Linux 2
Amazon Linux 2 ECS-Optimized Base AMIs
Amazon EKS-Optimized Amazon Linux AMIs
macOS 10.14.x (Mojave), 10.15.x (Catalina), and 11.x (Big Sur)
SUSE Linux Enterprise Server (SLES) 12 and 15
Ubuntu Server 16.04, 18.04, and 20.04
Windows Server 2008–2012 R2 AMIs published in November 2016 or later
Windows Server 2016, 2019, and 2022
To help you understand how to use Amazon System Manager (Run Command), I will guide you through a simple example and break down the steps involved.
The architecture
Step 1 — Choose a Systems Manager capability — choose a systems manager capability depending on what action you want to perform on your resources. The diagram below shows the capabilities that IT administrators and DevOps personnel use to manage their applications and resources.
And in this article, we are using “Run Command”.
Step 2— Create a set of EC2 instances
Create three (Amazon Linux 2) EC2 instances with the following tags (testing-1, testing-2, testing-3).
Step 3— Creating a Custom Command Document to create create a Directory with a file inside in all instance
To demonstrate RUN command capability, search for Systems Manager and click to open it, scroll down and you will find the Run command then click on it.
We are using a custom script to execute this task, and what the task would do is create a directory and also create a file inside the directory in all of the instances that we registered.
**Note: Depending on your use case, you can either use a shell script or AWS CLI Commands in the **SSM Run Command.**
Below is a simple shell script we will use to run our task.
mkdir name
cd name && touch olumoko.text autotxt
Step 4 — Follow the below configurations
Put in your script for the task in the space for commands.
Here is where you get to register the instances that you want the systems manager to execute the task on, and you can use any of the 3 options below depending on your use case, but I chose “choose instances manually” for this simple tutorial.
This page allows you to choose your output option, you can choose to send your output to an amazon s3 bucket by checking the “Enable an s3 bucket”
Now click on run and it will show you the progress of the execution.
Now that the systems manager said our task is successful we can connect to the instances one after the other to confirm if truly we have a Directory (name) and a file(olumoko) inside it.
Go to Ec2 and click on test-1 instance then click on connect and connect using session manager.
Now list the Directories and Files in the instance using the command ls -la to check if there is a directory with “name” then cd into the directory using the command cd name **to check if there is a file with the name **olumoko.txt in there.
So with this, you can make the systems manager perform your tasks for you on multiple instances with ease, and as a DevOps engineer, shortening the processes is one of the goals.
Useful Link To further dive into Amazon Systems Manager
What is AWS Systems Manager?
Hope this was helpful.
Have a great day!❤️
Posted on March 14, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024