I'm trying to create an AMI of an Ubuntu 18.04 EC2 that's configured with VNC.
I've successfully SSH'd into it and connected via a VNC Viewer. I then created an image from the running instance, however launching new instances from this image fails to start VNC again.
My VNC Setup:
After SSHing into my instance:
sudo apt update
sudo apt install xfce4 xfce4-goodies tightvncserver
vncserver # then set my password
vncserver -kill :1
Then I set ~/.vnc/xstartup to:
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Then it worked if I did: sudo chmod +x ~/.vnc/xstartup
and vncserver
Things I tried:
#!/bin/bash
vncserver
How can I create a custom AMI so I could launch an EC2 that autostarts a VNC server (or even starts the server after a user data script)?
Managed to do it with crontabs.
After killing the vncserver, I just ran:
crontab -e
Then chose my preferred editor and added @reboot vncserver :1
to the file.
From here, creating the image from the EC2 console was as simple as selecting the instance -> actions -> image -> create image.