- Newest
- Most votes
- Most comments
You can confirm which EC2 instances are running the CloudWatch agent using several approaches:
- Check the CloudWatch agent service status directly on each instance: You can use AWS Systems Manager Run Command to execute the following command across multiple instances:
sudo systemctl status amazon-cloudwatch-agent
This will show if the agent is running, stopped, or not installed.
- Use AWS PowerShell to query instances: You can use PowerShell to query EC2 instances and filter them based on specific criteria. For example:
$InstanceParams = @{ Filter = @( @{'Name' = 'instance-state-name';'Values' = @("running","stopped")} ) } $result = Get-EC2Instance @InstanceParams
You could then run a command against these instances to check the CloudWatch agent status.
- Use AWS CloudFormation to deploy and verify: If you're deploying the CloudWatch agent at scale, you can use CloudFormation to install the agent and track which instances have it installed. The CloudFormation template can target instances by:
- Specific instance IDs (comma-delimited list)
- Instance tags (specify TagKey and TagValue)
- Auto Scaling groups (using the tag key
aws:autoscaling:groupName)
- Systems Manager Run Command without tags: While you mentioned seeing examples with tags, you can also run commands against all managed instances without specifying tags. In the AWS Systems Manager console, when creating a Run Command, you can select "Choose instances manually" and then select all the instances you want to check.
For exporting the results to JSON, you can configure the Run Command to store command output in an S3 bucket, which would give you a file containing the status of the CloudWatch agent on each instance.
Sources
Logging EC2 Instances Bash Commands with CloudWatch Logs | AWS re:Post
Use DescribeInstances with an AWS SDK or CLI - AWS SDK Code Examples
CloudWatch solution: Amazon EC2 health - Amazon CloudWatch
Hello.
Use the Tag Editor to set the same tags for all EC2 instances.
The Tag Editor allows you to set tags for EC2 instances in a region in bulk.
https://docs.aws.amazon.com/tag-editor/latest/userguide/find-resources-to-tag.html
After that, try using SSM Run Command to find the EC2 instance where the CloudWatch Agent is running.
If you select AWS-RunShellScript as the command document, you can run commands on an EC2 instance running the Linux OS.
https://docs.aws.amazon.com/systems-manager/latest/userguide/running-commands-console.html
Relevant content
asked 9 months ago

Can you give me example of how to run without tags for run command ?