Cloning an EC2 Instance

AWS
DevOps
Archive
Clone an AWS EC2 instance via AMI and avoid the Apache 000-default.conf reset trap that breaks your site config on every new launch.
Author

B. Talvinder

Published

November 14, 2015

From the Archive

Originally published in 2015 on talvinder.com. Some technical details may be outdated, but this remains here as part of the archive.

Cloning an EC2 instance is straightforward via an AMI snapshot, but there is one Apache configuration pitfall that catches most people: the 000-default.conf file. When AWS provisions a new instance from your AMI, it recreates this default config file and it can silently override your custom virtual host settings, breaking your site with no obvious error.

The steps are simple — the trick is what to watch for after launch.

  1. Create AMI
  2. Launch new instance

While launching new instance, you can keep instance storage low. Keep EBS storage up to your needs.

If your site is located at /var/www/ and you use mod_rewrite of apache:

  1. If the conf of your site is located in /etc/apache2/sites-enabled/000-default.conf, chances are they will be rewritten
  2. Best practice is to create conf like: /etc/apache/www.domain.com.conf
  3. When new instance is created from AMI, 000-default.conf file is recreated. So make sure that either you delete the 000-default file or add the root domain path in it as well.

This is easy to miss because your AMI image contains the correct conf file, but the provisioning process overwrites it. Check this before declaring the clone successful.

Enjoyed this?

Get frameworks, build logs, and field notes in your inbox.

No spam. Unsubscribe anytime.