How do I check to see if the CloudWatch agent has been installed on any given instance using the CLI?

0

This would have been a cinch using the mon-version [https://docs.aws.amazon.com/AmazonCloudWatch/latest/cli/cli-mon-cmd.html#w2aab9c11b9] command, but it's no longer supported.

I have a script in place to loop through all the instances in all my accounts, but I have no easy way to verify whether or not the CloudWatch agent is running on any of them.

What is the best way to do that?

Jonny
asked a month ago415 views
1 Answer
1
Accepted Answer

you can adopt several approaches depending on the specific details of your environment, such as the operating systems of the instances and whether you're using AWS Systems Manager. Here are a couple of methods that might fit your needs:

  • Ensure AWS Systems Manager (SSM) Agent is installed on your instances.
  • Verify instances have IAM roles with permissions for Systems Manager.
  • Use AWS CLI with SSM send-command for checking CloudWatch agent status:
    • Linux: aws ssm send-command --document-name "AWS-RunShellScript" --targets "Key=instanceids,Values=<instance-id>" --parameters commands="sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status" --output text
    • Windows: aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets "Key=instanceids,Values=<instance-id>" --parameters commands="& 'C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' -m ec2 -a status" --output text
  • Alternatively, directly access instances via SSH (Linux) or Remote PowerShell (Windows) to check status:
    • Linux SSH: ssh user@instance-ip 'sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status'
    • Windows PowerShell: Invoke-Command -ComputerName instance-ip -ScriptBlock { & 'C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' -m ec2 -a status }
  • Integrate chosen method into your existing script for automated checking across all instances.
profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions