AWS: CloudWatch agent configuration file

Viewed 2877

I am trying to provide the CW agent configuration, regarding which files the latter should track;

According to this documentation, such info should be configured in /etc/awslogs/awslogs.conf (along with appropriate region setting in /etc/awslogs/awscli.conf).

However, this page indicates that log source (can also? / should?) be configured in /tmp/cwlogs/*.conf

Won't the second option (under /tmp) lead to the conf file being lost after a reboot?

Any idea what is the right place to store such configuration information?

1 Answers

it's better to install and configure CloudWatch log agent while creating a new instance using the userdata. That way whenever u spin up a new instance, you fetch latest agent version and also latest configuration file.

save the configuration file either in s3 or as a ssm parameter.

after installing the agent, you can start it by passing " -a fetch-config".

on how to start CloudWatch Agent is described in detail in the below link. link cloudwatch log agent check out "Start the CloudWatch Agent on an Amazon EC2 Instance Using the Command Line"

For example, if the ami is linux(amazon 2) and using config file. The below should do.

wget https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip
unzip AmazonCloudWatchAgent.zip
./install.sh
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:path-to-config-file.json -s
Related