13

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 this:

Launching interactive setup of CloudWatch Logs agent ... 

Step 1 of 5: Installing pip ...DONE

Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... 
Traceback (most recent call last):
  File "./awslogs-agent-setup.py", line 1144, in <module>
    main()
  File "./awslogs-agent-setup.py", line 1140, in main
    setup.setup_artifacts()
  File "./awslogs-agent-setup.py", line 696, in setup_artifacts
    self.install_awslogs_cli()
  File "./awslogs-agent-setup.py", line 523, in install_awslogs_cli
    subprocess.call([AWSCLI_CMD, 'configure', 'set', 'plugins.cwlogs', 'cwlogs'], env=DEFAULT_ENV)
  File "/usr/lib64/python2.7/subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

what directory or file is it missing?

lightweight
  • 3,227
  • 14
  • 79
  • 142
  • what platform (os / version) are you running this in? Afaik, the installation script does not install all platforms. – gsaslis Feb 02 '17 at 07:43
  • I'm using RHEL7 – lightweight Feb 02 '17 at 15:45
  • well, line 523 is `subprocess.call([AWSCLI_CMD, 'configure', 'set', 'plugins.cwlogs', 'cwlogs'], env=DEFAULT_ENV)` and AWSCLI_CMD is `/var/awslogs/bin/aws` . can you confirm if that exists? – gsaslis Feb 02 '17 at 20:32
  • I'm having this issue, and can confirm /var/awslogs/bin/aws is the file that's missing. – Eric Hydrick May 09 '17 at 21:17
  • It appears that this is being caused by the script detecting the presence of /var/awslogs/bin/activate - so it's not creating the virtual environment for awslogs, which I believe is what would install the /var/awslogs/bin/aws file. – Eric Hydrick May 09 '17 at 21:26
  • Here's another solution specifically for ubuntu 17.10 https://stackoverflow.com/questions/48817525/awslogs-agent-setup-py-not-working-on-ubuntu-17-10-artful/48817582#48817582 – Bruce Edge Feb 15 '18 at 23:25

7 Answers7

6

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

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
5

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
Milan Cermak
  • 7,476
  • 3
  • 44
  • 59
2

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!

1

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
rednax
  • 225
  • 1
  • 2
  • 13
0

^^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

user2966600
  • 571
  • 4
  • 4
0

So guys Just figured it OUT!!

File "./awslogs-agent-setup.py", line 520, in install_awslogs_cli venv_in_path = (subprocess.call(["which", "virtualenv"], stderr=self.log_file, stdout=self.log_file) == 0)

On the above error, you can the "which" command is being used and unfortunately "which" was not installed. Once installed everything started working.

Cheers!! If it helps anyone.

0

I know I'm 2+ years late but I wasn't able to find an answer to this.

I was having the same problem and it was because the disk was running out of inodes (I think running out of disk space can cause the same problem) and I solved it running sudo apt-get autoremove

You can check your inodes with df -i

I hope this may help anyone having this problem.

Juanín
  • 841
  • 6
  • 16