The AWS CloudWatch service is used for real-time monitoring and observation of AWS Cloud services. Logs, metrics, and events are used to collect data. We may utilise AWS CloudWatch in production environments to discover Cloud infrastructure issues and other cloud operations concerns, set alarms, and take automated actions to keep our apps running smoothly.
AWS CloudWatch Agent is a software package that runs continuously on our EC2 servers and provides system-level and in-guest metrics. It can also collect logs and metrics from containerized applications.
Before installing CloudWatch Agent on our EC2 instance we need to attach an IAM role to it with appropriate permissions.
To create an IAM role follow these steps:
- Go to AWS Console->IAM->Roles->Create Roles.
- Select AWS service as the trusted entity type and EC2 as use case. Click Next.
- Enter “CloudWatchAgentServerPolicy” in search bar of permissons page. Select the policy and hit next.

- Give a name to your role and click on create role.
- Go to EC2 console. Select your instance in which you want to install CloudWatch Agent package.
- Go to Actions->Security->Modify IAM Role.
- Select the role you created and click on Save.

- Restart the EC2 instance.
Steps to install the CloudWatch Agent on an Ec2 Instance:
Step1: Connect to your EC2 instance.
Step2: Install the cloud watch agent package. For Red Hat Machine copy the following code for downloading.
wget https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm
Step3: Install the package. Move to the directory where you have downloaded the package and run the following command.
sudo rpm -U ./amazon-cloudwatch-agent.rpm
Step4: Create the configuration file with the help of cloud watch wizard. Run the following command for starting cloud watch wizard.
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
Step6: Answer the questions to customize your configuration file. Either you can select default options or choose according to your use case.
Step7: You can manually change the configuration file later as well. The file is located at following location.
/opt/aws/amazon-cloudwatch-agent/bin/config.json

Step7: Start the CloudWatch Agent with the following command.
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s
Step8: The CloudWatch agent is now installed and configured on your EC2 Instance. Now, wait for a few minutes to collect the data. Goto the Cloudwatch section->Metrics-> cwagent.

Contact us if you need assistance with cloud infrastructure-related issues or Technology Consulting to manage entire stack. We also help you hire experienced cloud engineer. You can also Hire Dedicated software developer in India, Virtual CTO Services for cloud strategy services in India , IT staff augmentation services, and product management best practices.
