Skip to content

How to update clodwatch agent config on a Ec2

0

Hello,

I already have a Cloud Watch agent running on an EC2 with a basic configuration. What would be the best way to add a log file to the agent? I'm assuming if I run the wizard it might replace the existing configuration at /opt/aws/amazon-cloudwatch-agent/bin/config.json. Can I directly edit the /opt/aws/amazon-cloud watch-agent/bin/config.json file and restart the agent?

What is the /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml file?

asked 2 years ago1.3K views

1 Answer
0
Accepted Answer

To update the CloudWatch agent configuration on an EC2 instance to add a new log file, you have a few options:

  1. Directly edit the existing configuration file: You can directly edit the /opt/aws/amazon-cloudwatch-agent/bin/config.json file to add the new log file. After making changes, you'll need to restart the agent using the fetch-config option to ensure the new configuration is applied.

  2. Use the CloudWatch agent configuration wizard: While running the wizard might replace the existing configuration, you can use it to generate a new configuration file and then manually merge the new settings with your existing configuration.

  3. Create a new configuration file: You can create a new JSON configuration file with the additional log file settings and use it to update the agent.

After making changes to the configuration, regardless of the method used, you should restart the CloudWatch agent using the following command:

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

This command tells the agent to fetch the updated configuration and start with the new settings.

Regarding the amazon-cloudwatch-agent.toml file: The .toml file is an intermediate configuration file used by the CloudWatch agent. It's generated from the JSON configuration file and contains the actual configuration used by the agent at runtime. You shouldn't need to modify this file directly; instead, focus on updating the JSON configuration file.

Sources
Issue with CloudWatch agent configuration | AWS re:Post
Install and run the CloudWatch agent on your servers - Amazon CloudWatch
Troubleshooting the CloudWatch agent - Amazon CloudWatch

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Is there a way to instruct the wizard to generate the new configuration file at a different location? Or simply take a backup of the existing config.json before running the wizard then compare it with the newly created config.json?

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.