New to EC2 Instance User Data scripts and I’m struggling here. I can create an EC2 Instance from one of my Launch Templates without issue. I can then SSH into that instance and run the following commands manually, which (collectively) install the CodeDeploy Agent (I’m on Ubuntu 20.04):
sudo apt update
sudo apt -y install ruby-full
sudo apt install wget
cd /home/ubuntu
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto > /tmp/logfile
I can then test to see that CodeDeploy Agent is running via: sudo service codedeploy-agent status, and I see it is clearly running + working properly.
Now I’m trying to create a new EC2 Instance from the same Launch Template, except this time, I’m trying to define the exact same script as above in User Data. So at the very bottom of the Advanced details section, it presents you with a huge text area labeled User data. I copy and paste the exact same script from above (as-is), and click Launch instance.
It typically takes about 2 mins for my instances to become healthy + initialized, and the script above takes about 1 minute to install CodeDeploy Agent. I waited 10 minutes, SSHed onto the instance, ran my sudo service codedeploy-agent and…nothing:
sudo service codedeploy-agent
Unit codedeploy-agent.service could not be found.
What am I doing wrong here? I’m definitely waiting long enough. Same exact script, same exact launch template. The only difference is running the commands manually vs. through the User Data section of the Launch Template UI.