1. Install AWS CLI (if not already installed):

 

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

unzip awscliv2.zip

sudo ./aws/install

 

  1. Create an IAM User with Proper Permissions:

 

A screenshot of a computer

Description automatically generated

 

 Generate Access Key and Secret Access Key for the user

 

  1. Install the CloudWatch Agent:

 

wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

 

sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

A black screen with a black background

Description automatically generated

  1. Configure AWS Credentials:

 

aws configure

 

sudo aws configure --profile AmazonCloudWatchAgent

 

AWS Access Key ID [None]: 

AWS Secret Access Key [None]: >

Default region name [None]:

Default output format [None]:

 

  1. Create CloudWatch configuration file to collect memory and Disk usage metrics

 

sudo vi /opt/aws/amazon-cloudwatch-agent/bin/config.json

{
"agent": {
"metrics_collection_interval": 60
},
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
}
}
}
 }

 

  1. Modify the CloudWatch Agent Configuration File :

 

      sudo vim /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml

 

Press “I” to enter insert mode in Vim, and uncomment this line

[credentials]
 shared_credential_profile = "AmazonCloudWatchAgent"

Press “ESC”, and then type “:wq!” to save the file and exit Vim.

 

  1. Start the CloudWatch Agent and check the status :

 

sudo amazon-cloudwatch-agent-ctl -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -a fetch-config -s

 

sudo systemctl status amazon-cloudwatch-agent

 

  1. Verify metrics in CloudWatch

A screenshot of a search box

Description automatically generated

 

  1. Push JSON Configuration to Systems Manager Parameter Store:

 

aws ssm put-parameter --name "CloudWatchAgentForAppServer02-Config" --type "String" --value file:///opt/aws/amazon-cloudwatch-agent/bin/config.json

 

 

 

  1. Verify this in SSM Parameter Store

 

A screenshot of a computer

Description automatically generated