Friday, February 4, 2022

[SOLVED] How can I use Python (boto3) to determine which EC2 instances have CloudWatch agents?

Issue

I am writing a Python script to determine which EC2 instances have CloudWatch agents installed and which do not. I got some information from href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html#CloudWatch-Agent-troubleshooting-verify-running" rel="nofollow noreferrer">CloudWatch Agent Troubleshooting but don't know how to implement it programmatically. Do I use SSM, EC2, or something else?


Solution

I'm not aware of external visibility into the status of a particular EC2 instance's CloudWatch Agent.

If your EC2 instances have the SSM Agent preinstalled then you could use boto3 to invoke SSM Run Command to run a collector scripts on each instance (example).



Answered By - jarmod
Answer Checked By - Mildred Charles (WPSolving Admin)