How to Install AWS CloudWatch Logs Agent on Ubuntu Using apt-get Instead of yum


2 views

The AWS CloudWatch Logs agent package structure differs between RHEL-based systems (using yum) and Debian-based systems (using apt). While RHEL systems have the awslogs package in their default repositories, Ubuntu requires additional setup.

The recommended way to install the CloudWatch Logs agent on Ubuntu is:

curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
sudo python3 ./awslogs-agent-setup.py --region us-east-1

For those preferring apt-get, you can add the AWS repository:

sudo apt-get update
sudo apt-get install -y wget
wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
sudo python3 awslogs-agent-setup.py --region us-west-2

After installation, configure /var/awslogs/etc/awslogs.conf:

[general]
state_file = /var/awslogs/state/agent-state

[/var/log/syslog]
file = /var/log/syslog
log_group_name = /var/log/syslog
log_stream_name = {instance_id}
datetime_format = %b %d %H:%M:%S

Check service status and logs:

sudo service awslogs status
sudo tail -n 50 /var/log/awslogs.log

Common service commands:

sudo service awslogs start
sudo service awslogs stop
sudo service awslogs restart

When working with AWS services on different Linux distributions, you'll notice that the package names and installation methods vary. The AWS documentation primarily shows RHEL/CentOS commands using yum, but Ubuntu/Debian systems use apt-get.

For Ubuntu/Debian systems, AWS provides a different package name and installation method:

sudo apt-get update
sudo apt-get install -y awscli cloud-init

However, if you specifically need the CloudWatch Logs agent, you'll need to:

Since there isn't a direct apt-get equivalent for awslogs, you have several options:

Method 1: Using AWS CLI Configuration

curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
sudo python ./awslogs-agent-setup.py --region us-west-2

Method 2: Manual Configuration

Create a configuration file at /var/awslogs/etc/awslogs.conf:

[general]
state_file = /var/awslogs/state/agent-state

[/var/log/syslog]
file = /var/log/syslog
log_group_name = /var/log/syslog
log_stream_name = {instance_id}
datetime_format = %b %d %H:%M:%S

After installation, check the service status:

sudo service awslogs status
sudo tail -f /var/log/awslogs.log

If you encounter permission issues:

sudo chmod 755 /var/awslogs/etc
sudo chmod 644 /var/awslogs/etc/awslogs.conf

For connectivity problems, verify your IAM role has logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents permissions.