1

the userdata script for my ec2:

#!/bin/bash
curl https://raw.githubusercontent.com/erjan/MyVoteAWS/main/vote-processor/processor.py > /home/ec2-user/processor.py
cd /home/ec2-user/
sudo chmod +x processor.py
sudo yum -y install python3-pip
sudo yum -y install python3 python3-setuptools
pip3 install boto3 --user                   #this is not executed
./processor.py

the file processor.py is pulled from my github, i do see it, but its not launched cuz it needs boto3 - gives error

"Import error: no boto3 module found"

i have to wait till it shows '2/2 checks passed' in the aws gui, then connect, then do explicitly type "pip3 install boto3 --user", then i see progress bar downloading boto3, then my script processor.py works.

but it does not work out of box from userdata. What is the reason?

Marcin
  • 215,873
  • 14
  • 235
  • 294
ERJAN
  • 23,696
  • 23
  • 72
  • 146

1 Answers1

1

Please run your script using python3

python3 processor.py

Otherwise it runs probably under python2, which does not have boto3 installed.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • ok i will try, but when i did pip3 show boto3 (pip for version python3) - it still showed that no boto module was installed.. – ERJAN Jan 16 '23 at 11:02
  • @ERJAN user-data runs under `root` user, not `ec2-user`. So if you just run `pip3 install boto3 --user` it will install in `root`, not `ec2-user`. – Marcin Jan 16 '23 at 11:22
  • ok what i did was replace it with "sudo pip3 install boto3", it worked. however the script is not running - "./processor.py" is not launched when i login.. how to fix it? – ERJAN Jan 16 '23 at 15:36
  • @ERJAN Script not working is a new issue for new question. My answer and comments correctly address your original issue that you reported. – Marcin Jan 16 '23 at 21:46