Running FTP server on EC2 on demand

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.

Advertisements

2 thoughts on “Running FTP server on EC2 on demand

  1. Pingback: EC2 Server on demand without elastic IP | The JavaDude Weblog

  2. Pingback: Running EC2 spot instances | The JavaDude Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s