pythonamazon-web-servicesshellboto3ec2-userdata

Userdata partially working but not installing boto3 on EC2 launch, have to explicitly install it


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 repo, I do see it, but it's not launched because 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?


Solution

  • Please run your script using python3

    python3 processor.py
    

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