Cloning an EC2 Instance
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.
- Create AMI
- 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:
- If the conf of your site is located in
/etc/apache2/sites-enabled/000-default.conf, chances are they will be rewritten - Best practice is to create conf like:
/etc/apache/www.domain.com.conf - When new instance is created from AMI,
000-default.conffile is recreated. So make sure that either you delete the000-defaultfile 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.