I'm creating a custom Ubuntu AMI using Packer and then using it to launch an EC2 instance, which then has an application deployed to it using CodeDeploy.
On this instance I need to use Python3.7 as I'm using some datetime functionality that isn't supported in 3.6 - default python3 version for Ubuntu is Python3.6.8
The problem I have is that when installing python modules via pip using python3.7, launching the custom AMI fails, it never reaches a healthy state. When I install the same modules via default python3 there is no issue.
Packages are installed via a script as below during packer build:
#!/bin/bash
# wait for cloud-init to finish - other wise apt install can fail
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
echo 'Waiting for cloud-init...'
sleep 1
done
# Install apt packages
sudo apt-get update -y
for package in unzip jq python3.7 python3-pip ruby wget mysql-client-5.7
do
sudo apt-get install -y $package
done
# Install python packages
sudo python3.7 -m pip install --upgrade pip --no-cache-dir
sudo python3.7 -m pip install --upgrade awscli --no-cache-dir
sudo python3.7 -m pip install --upgrade boto3 --no-cache-dir
sudo python3.7 -m pip install -r /tmp/requirements.txt --no-cache-dir
# Install and start codedeploy agent
wget https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start
sudo service codedeploy-agent status
The above code works, but the custom AMI won't reach a healthy state.
The below code works AND the custom AMI launches without any issues:
#!/bin/bash
# wait for cloud-init to finish - other wise apt install can fail
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
echo 'Waiting for cloud-init...'
sleep 1
done
# Install apt packages
sudo apt-get update -y
for package in unzip jq python3.7 python3-pip ruby wget mysql-client-5.7
do
sudo apt-get install -y $package
done
# Install python packages
sudo pip3 install --upgrade pip --no-cache-dir
sudo pip3 install --upgrade awscli --no-cache-dir
sudo pip3 install --upgrade boto3 --no-cache-dir
sudo pip3 install -r /tmp/requirements.txt --no-cache-dir
# Install and start codedeploy agent
wget https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start
sudo service codedeploy-agent status
Any ideas what could be causing instance failure? The only difference is how the python modules are installed.
Edit - commands have been tested locally without apparent issues.