Installing the CloudWatch Agent on an EC2 Instance – CloudWatch and CloudWatch Metrics – SCS-C02 Study Guide

Installing the CloudWatch Agent on an EC2 Instance

In order to install the CloudWatch agent on an EC2 instance, you will need to have an EC2 instance that is running and with which the SSM can communicate successfully. One of the easiest ways to do this is to use an EC2 instance running Amazon Linux. If you are using a different variety of operating system, there are ways to get SSM Agent running on your system. Sometimes it has to be manually installed, as in the case of the Ubuntu operating system.

You will first launch an EC2 instance to carry out the exercise:

  1. Direct your browser to the EC2 service using the following URL: https://packt.link/aGtjo.
  2. You will be brought to the EC2 dashboard. Click on the orange button labeled Launch instance in the middle of the page. When it pops up, choose Launch instance again.
  3. On the Launch an instance page, name your instance CloudWatchAgentTest.
  4. For the AMI, choose the latest Amazon Linux AMI; this example has the Amazon Linux 2023 AMI selected. Select the following parameters:
    1. Instance size: t2.micro is OK to keep.
    1. Key pair: Keep this blank as we will use SSM to manage this instance.
    1. Network Settings: Create a security group to SSH from your IP address.

Figure 8.8: Key pair selection screen for EC2 instance

  • Click Advanced details to expand the settings; under the IAM instance profile, click on the drop-down box and choose the CloudWatchAgentServerRole role you created in the previous step.
  • Once you have completed all this, click the Launch instance button on the bottom right-hand side of the page.

Once you have an Amazon Linux EC2 instance up and running, you can move on to installing the CloudWatch agent.

  • Navigate to the Systems Manager service in the AWS Management Console either by searching for the service in the search bar at the top or by using the following URL: https://packt.link/V1KKl.
  • From the left-hand menu, under the Node Management menu heading, choose the Run Command menu item.

Figure 8.9: Node Management menu

  • Next, click the orange button in the main window labeled Run a Command.
  • On the Run a command screen, use the search box to search for the document named AWS-ConfigureAWSPackage. Select the radio button next to the document once it is found.
  •  Scroll down to the Command Parameters section of the page. The name of the package to install is AmazonCloudWatchAgent. You should be able to keep the default action of Install and keep Installation Type as Uninstall and reinstall. You do not have to fill in any values for the Version or the Additional Arguments sections.

Figure 8.10: Command parameters screen for running a command

  1. After filling in the command parameters, scroll down on the page until you reach Target selection. This is where you will search for the EC2 instance you just launched, CloudWatchAgentTest. You can do this by manually selecting the radio button in the box at the center labeled Choose instances manually and then selecting your instance.

Figure 8.11: Instance selection screen for CloudWatch