Skip to content Skip to sidebar Skip to footer

Having Trouble Installing Awslogs Agent

I'm having issues trying to instal awslogs agent on my ec2 node. When I run this command: sudo python ./awslogs-agent-setup.py --region us-east-1 it seems to fail at step 2 like t

Solution 1:

Amazon Linux 2

The awslogs agent is available now as a yum package https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html

sudo yum install -y awslogs
sudo systemctl start awslogsd
sudo systemctl enable awslogsd.service

Make sure to change the AWS Region as mentionned in the doc

Solution 2:

I solved this by passing the python interpreter to be used:

sudo python ./awslogs-agent-setup.py --region us-east-1 --python=/usr/bin/python3.5

Solution 3:

Although this question is a bit old, I'd like to add an answer to it, as I recently run into the same problem, but managed to find a way around it. I was trying to install this in an instance running CentOS 7.

When I run the installation command for the first time, I got exactly the same error log reported by @user2061886. The installer logs to a file with the following path: /var/log/awslogs-agent-setup.log. I tailed the file and found that internally the installer was complaining about not being able to find the file "Python.h":

    creating build/temp.linux-x86_64-2.7
    checking if libyaml is compilable
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-
D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-
size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/check_libyaml.c -o build/temp.linux-x86_64-2.7/check_libyaml.o
checking if libyaml is linkable
gcc -pthread build/temp.linux-x86_64-2.7/check_libyaml.o -L/usr/lib64 -lyaml -o build/temp.linux-x86_64-2.7/check_libyaml
building '_yaml' extension
creating build/temp.linux-x86_64-2.7/ext
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c ext/_yaml.c -o build/temp.linux-x86_64-2.7/ext/_yaml.o
ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
    compilation terminated.
    error: command'gcc' failed with exit status 1

I couldn't get it working with Python 2.7, so I switched to Python 3.5. To install Python 3.5 in CentOS 7:

yum -y udpate

yum install -y epel-release

yum install -y http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-
release-1.0-13.ius.centos7.noarch.rpm

yum -y update

yum install -y python35u*

I run again the installer command and got passed the error reported by @user2061886. I could install and configure the CloudWatch Logs Agent. However, soon after I started the service (sudo service awslogs start), I run into a second problem. This time I had to tail the following file to spot the issue: /var/log/awslogs.log. The cloudwatch logs agent was basically complaining about not being able to find the cwlogs package:

Traceback (most recent call last):
  File "/var/awslogs/bin/aws", line 27, in <module>
    sys.exit(main())
  File "/var/awslogs/bin/aws", line 23, in main
    return awscli.clidriver.main()
  File "/usr/lib/python3.5/site-packages/awscli/clidriver.py", line 55, in main
    driver = create_clidriver()
  File "/usr/lib/python3.5/site-packages/awscli/clidriver.py", line 64, in create_clidriver
    event_hooks=emitter)
  File "/usr/lib/python3.5/site-packages/awscli/plugin.py", line 44, in load_plugins
    modules = _import_plugins(plugin_mapping)
  File "/usr/lib/python3.5/site-packages/awscli/plugin.py", line 58, in _import_plugins
    plugins.append(__import__(path))
ImportError: No module named 'cwlogs'

I solved this by installing the package manually with pip:

pip3.5 install awscli-cwlogs. 

This got the problem solved!

Solution 4:

I had the same problem trying to install on centos docker. Turns out I could do without updating python after installing these packages

python-devel libpython-dev which initscripts cronie

Solution 5:

^^Yeah.. I fixed a similar issue with some missing dependencies that were pointed to in the /var/log/awslogs.log


apt-get update && apt-get install -y python-pip libpython-dev

Post a Comment for "Having Trouble Installing Awslogs Agent"