or ‘How to cut (even more) cost while running EC2 instances‘
I am running a FTP server on an EC2 instance (micro if you want), but we dont use it all the time. The server is run on-demand only and auto-shutdown every night. The challenge: on every new start of the instance you will get a new public ip which screws your passive ip address configuration in vsftpd.conf.
- How to install and run vsftp on an EC2 Ubuntu instance.
- How to switch off a Ubuntu EC2 instance ? Add this to the crontab:
login as root crontab -e add: 0 12 * * * /sbin/shutdown \-h now
- How to update vsftp.conf on start up ?
pubip=`curl http://169.254.169.254/latest/meta-data/public-ipv4` sed "s/pasv_address=.*/pasv_address=$pubip/" /etc/vsftpd.conf > /etc/vsftpdTEMP.conf rm /etc/vsftpd.conf mv /etc/vsftpdTEMP.conf /etc/vsftpd.conf service vsftpd restart
curl http://169.254.169.254/latest/meta-data/public-ipv4 gives you the public IP address of your instance.
Remaining challenge: If you dont want to spend money on an elastic (permanent) IP which costs you while the instance is NOT running, you need a DNS service like dyndns.com and update the dyndns entry on every start too. This can easily done by a shell script using ddclient or Ubuntu’s dyndns command.