I am creating aws ec2 Ubuntu 18.04 LTS using cloud formation template and have user data to run commands during launch of instance. In user data, command is written to install python3.8:
apt-get install python3.8 -y
This cloud formation / user data is not installing python 3.8 on ec2 instance (checked after running command: python3.8 --version on ssh client). If manually connect instance with ssh client (putty) and run apt-get install python3.8 -y , it install python 3.8 on instance. I analysed cfn-init.log & cfn-init-output.log at /var/log/ on ec2 instance, but didn't find any useful information for python3.8
Can anyone help me to find why cloud formation template / user data is not installing python3.8 but ssh client (putty) can install python3.8
The user data section is as below:
UserData:
"Fn::Base64":
"Fn::Sub":
- |
#!/bin/bash
# Install Python dependencies
apt-get update
apt-get update && apt -y upgrade
apt-get install dos2unix
apt-get install -y python-pip
apt-get install -y python3.6 python3-pip
apt-get install python3.8 -y # installing python3.8
pip3 install --no-cache-dir NumPy
# Install AWS cli and init functions
pip3 install --no-cache-dir awscli
pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
ln -s /usr/local/bin/cfn-hup /etc/init.d/cfn-hup
cfn-init -v --stack ${STACK} --resource resources --configsets install --region ${REGION}
- { STACK: !Ref "AWS::StackName" , REGION: !Ref "AWS::Region" }
CodePudding user response:
UserData runs only on instance first launch. Changes of UserData in Cloud Formation do not force instance replacement, so your new UserData never executes.
You have to manually delete the stack, which will delete the instance, and redeploy it.
CodePudding user response:
That EC2 user-data installed python3.8 and pip successfully for me:
#!/bin/bash
apt-get update
apt-get upgrade -y
apt install python3.8 -y
apt install python3.8-distutils -y
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py