16

I'm just getting started with AWS EC2 and not entirely sure I understand it.

From what I've read, an instance is basically a virtual server, and you should be able to somehow "duplicate" that virtual server from the AWS console somehow. Then use Load Balancer or Elastic IP to route requests to one or the other.

The problem comes in when I try to "duplicate" my instance. I tried a million things, but the only thing that got me close was creating an AMI of my current instance then launching an instance from that, but when I did that, the new instance was basically the default server config. None of my files were there.

What am I doing wrong?

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
Charles Zink
  • 3,482
  • 5
  • 22
  • 24
  • 1
    Where are you storing your files that you'd expect to be part of the AMI? On the instance itself or on an EBS volume? – Daan Feb 15 '12 at 16:40

3 Answers3

14

You don't really "duplicate" the instance. You more copy it as a "blueprint". Then when you boot an instance later, you can base that instance off of your snapshot or "blueprint".

The ELB can be configured to point at any instance you want, so when you boot a new server off this snapshot/"blueprint" it can be automatically added to the ELB.

Now that is cleared up, to answer the question:

  1. I would make sure to use EBS backed instances. You can find them all over. But not S3 backed. If they EBS backed then the exact volume with all your configs will be there.

  2. I would make sure your instance is configured how you like it and has proper scripts installed for when it boots up. You will want your services started, config files pulled down from repositories, etc. The config files should be there, but I would not rely on that. If you have them in a repository and then make a startup script to pull them down and copy them where you want, you will be in much better shape.

  3. With the instance running and selected, click on the instance actions drop down and click "Create AMI"

  4. The instance will REBOOT. So be careful.

  5. Launch a new instance. And pick the AMI/Snapshot that #3 created.

  6. Done. Check this https://stackoverflow.com/a/8919031/667608 that could help with the above.

Oh, one other thing, if you have any EBS Volumes attached, they will also be copied, but you will need to mount them once the server boots.

Community
  • 1
  • 1
chantheman
  • 5,256
  • 4
  • 23
  • 34
  • 2
    If you are using the instance in production, etc. Now Amazon has an option to not reboot, but it does not guarantee the volumes will not be corrupted. I would only use this option if you know there are not a lot of processes writing to disk at the time of reboot. – chantheman Sep 04 '12 at 14:45
  • 1
    Anything running on it will be dead while it reboots – chantheman Oct 19 '12 at 22:28
2

Under instances, click on the image you want to duplicate and then go to instance action(its near the top) and create ami.

This creates a snapshot of your image as it is right now. Then when you need to add more power, you can simply launch that ami and have the load balancer distrubute the traffic between those ami's.

On a side note, unless really required, I would not suggest you store data on the ami if its changing and you plan to use it on another launched ami. You'll pretty much have to keep taking ami snapshots to update it with the new data, so instead figure a way to maintain state somewhere else(not sure about your data but you can consider a database, s3, or another server that these servers can mount to get the same data).

Hope that helps!

Lostsoul
  • 25,013
  • 48
  • 144
  • 239
  • Thanks! So your recommendation would be to store my code (I used Amazon's "Single EC2 Instance web server with Amazon RDS database instance" template to get started) on S3, and then mount that somehow on the AMI? How would I go about doing that? Sorry, first time using AWS and it's confusing as hell. – Charles Zink Feb 16 '12 at 05:28
  • 1
    Yes thats what I do. There are so many ways to do it, if you google s3 access ___(insert your programming language here), you'll find tools for this. If you don't like that you can use other tools to automatically sync with s3(outside your program). Personally, I'm not using s3, I'm using github to pull the fresh code everytime my apps start. – Lostsoul Feb 16 '12 at 15:09
  • Its really confusing, I suggest you start with the micro instance(it'll be slooow but cheap) and experiment. Remember if you mess anything up, you can always terminate the instance and start again. – Lostsoul Feb 16 '12 at 15:10
0

Create a webserver AMI using EBS backed instance. This will serve as your template for running multiple web-server instance later.

For the app codes, depending on your strategy and amount of files to transfer, you can pull them from S3 or git or maybe using a centralized filesystem such as NFS.

Configure the ELB, add one or more web server instances to it. CNAME your ELB's public dns to your www.domain.com.

Rodney Quillo
  • 3,312
  • 1
  • 18
  • 9