Managing Amazon EC2 instances has become smarter thanks to the Amazon Systems Manager (SSM) Agent. This effective tool connects AWS Systems Manager with your instance's operating system, enabling remote command execution, task automation, and smooth inventory management.What does the SSM Agent do?The SSM Agent is a program that operates on an EC2 instance, facilitating interaction between the AWS Systems Manager and the instance. It provides various functions, such as:Execute shell commands from a distance with the Run Command feature.Manager of Sessions: Protecting terminal sessions without using RDP or SSH.Patch Manager: Simplify the operating system and application patching processes.Stock: Compile instance data for compliance and management needs.If the SSM agent is not pre-installed, then you may have to manually install it for different operating systems or custom AMIs.What Are the SSM Agent Installation Requirements?It is important to assess certain key prerequisites before installing the SSM agent on an EC2 instance:IAM Role having Required Permissions:The EC2 instance needs an IAM role that provides the necessary permissions for the AWS Systems Manager. This usually involves adding the code “AmazonSSMManagedInstanceCore” policy, enabling the instance to interact with the Systems Manager and utilize its associated functionalities.Connectivity within a network:For the SSM Agent to work correctly, your EC2 instance needs to be able to connect to the internet or a Systems Manager VPC endpoint. Public instances can connect to the internet without any restrictions, whereas private instances require a VPC endpoint to communicate with the AWS Systems Manager. Installation of Package Manager completed:Make sure the necessary package manager is accessible for installation based on the operating system of your EC2 instance (Linux, Windows, etc.). For Amazon Linux, use yum, and for Ubuntu, use apt-get on Linux instances. On Windows, make sure the instance can execute the SSM installer.How to Install the SSM Agent on EC2 Instance?Setting up the Amazon SSM Agent on an EC2 instance is a simple procedure, although it may differ slightly based on the instance's operating system. Here is the method for installing it on various platforms:1. Check if the SSM Agent has been installed:Before installing the SSM Agent, check if it is currently installed and active.Linux (Amazon Linux, Ubuntu):Code:systemctl status amazon-ssm-agentIf the status is active, it indicates that the agent has been installed and is now operational.-Windows operating system:Access Services or enter services.msc in the Run box.Search for AmazonSSMAgent.If the agent is not present, proceed with the installation steps provided.2. Install the SSM Agent on Amazon Linux or Amazon Linux 2:Update system packages:Code:sudo yum update -yInstall the SSM Agent:Code:sudo yum install -y amazon-ssm-agentEnable and start the agent:Code:sudo systemctl enable amazon-ssm-agent sudo systemctl start amazon-ssm-agent3. Install the SSM Agent on Ubuntu:Update system packages:Code:sudo apt-get updateInstall the SSM Agent:Code:sudo snap install amazon-ssm-agent --classicEnable and start the agent:Code:sudo systemctl enable amazon-ssm-agent sudo systemctl start amazon-ssm-agent4. Install the SSM Agent on Windows:Download the SSM Agent Installer:Visit the official SSM Agent download page.Choose the suitable version for your Windows operating system.Run the Installer:Start the installer, then adhere to the installation guidelines.Start the Agent:Open Services, locate AmazonSSMAgent and click Start if it’s not already running.5. Verify the SSM Agent Installation:After installation, confirm that the agent is operating:Linux:Codesystemctl status amazon-ssm-agentWindows:Use the following PowerShell command:CodeGet-Service -Name AmazonSSMAgent6. Test the SSM Agent Installation:Sign in to the AWS Management Console.Go to Systems Manager and then click on Managed Instances.If the case does not materialize:Check the IAM's role and corresponding policy.Validate the connection to the Systems Manager endpoint.7. Automate SSM Agent Installation:You can automate the SSM Agent installation using a user data script when launching an EC2 instance.Code:#!/bin/bash sudo yum update -y sudo yum install -y amazon-ssm-agent sudo systemctl enable amazon-ssm-agent sudo systemctl start amazon-ssm-agentAdd this script to the User Data section during instance creation.Troubleshooting some of the Key SSM Agent Issues on EC2 Instances:When utilizing the SSM Agent on EC2 instances, you might come across certain typical problems. Listed below are some issues along with their corresponding troubleshooting resolutions:SSM Agent Failing to Begin:Failure to start the SSM Agent is commonly caused by installation problems, absence of dependencies, or issues with system configuration. For problem-solving:Inspect the agent’s logs for any error notifications.Install the agent again or update it to make sure it is the most recent version available.Make sure the instance has adequate resources, such as memory, to support the agent's operation.Instance Not Showing in Managed Instances:If your EC2 instance is not visible in the AWS Systems Manager interface, it may be due to:IAM Role Issues: Assure that the EC2 instance's IAM role contains the AmazonSSMManagedInstanceCore policy to avoid IAM role issues.Connectivity of the Network: Make sure the instance can connect to the Systems Manager through either the internet or a VPC endpoint.Errors related to authorization:If you encounter authorization problems, it probably indicates that the IAM role linked to the instance lacks the required permissions to interact with the Systems Manager.Verify the role's policy to make sure the correct permissions are given.Resolving these typical issues ensures that the SSM Agent operates effectively and manages your EC2 instances effectively.Bottom LineIt is important to install the SSM Agent on EC2 instances to fully utilize AWS Systems Manager's capabilities. You can set up and configure the SSM Agent on different operating systems by adhering to the steps mentioned earlier.Make sure your instances have the right IAM role and network configuration to fully utilize the advantages of a Systems Manager. Having the SSM Agent installed enables efficient automation of tasks, improved security, and simplified management of EC2 instances.Read Morehttps://devopsden.io/article/how-to-install-docker-on-an-ec2-instanceFollow us onhttps://www.linkedin.com/company/devopsden/