Ok, first post is going to be quick and easy. It’s been a while since I said I would post something and when I ran across this I figured I would start adding content to the site.
Let’s assume the following:
- You built an environment using CloudFormation or by hand and gave your instance user-data to run. In this case, it was to install OpenVPN on an Ubuntu server.
- Your Security Groups were designed by someone who knew what they were doing but you forgot to attach the one that allows outbound on 80 which prevented the server from installing OpenVPN.
- You have fixed your Security Group issue and you have full ssh access to the server and rather not rebuild – you just want to re-run the user-data.
Here is an option. I am by no means saying this is your only option, but it works and it was simple to do.
- Log in using ssh with your pem key.
- Run the following:
sudo curl https://169.254.169.254/latest/user-data >/usr/local/bin/udrun.sh sudo chmod +x /usr/local/bin/udrun.sh sudo udrun.sh
- Complete your OpenVPN configuration (sudo passwd openvpn, etc…)
What this does is grab your current user-data from the self hosted site on your EC2 instance, copies it to a local bash file, gives that file execute permission and then runs it.
Voila! Your user-data now ran properly.
For more information using on using local meta-data and user-data please the AWS documentation @ https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html