ELB Web Server on VPCSeptember 6, 2013
The background for this article is mostly spelled out in the last post I did on how to create a SSH Gateway Server on VPC. This builds on that, and shows how to create a public-facing web server on using an Elastic Load Balancer (ELB). However, this article may be run standalone.
Note: In order to create a quick web server, I made an AMI out of
a stock Ubuntu 13.04 server that I used
sudo apt-get apache2 php5, and
then added a
info.php script to just get some output about the
machine. If you are following along, you can do the same, or configure
the web sever however you’d like.
Again, all of my examples will be in ruby using the
aws-sdk gem, but the same
results can be achieved using any of their other SDKs.
- You have a basic undertsanding of AWS
- You already have an active AWS account
- You have a keypair called
~/.ec2/key-lab.pem(rename where appropriate)
- All commands are probably best done in
irb, this way you can inspect objects as you go along. Make sure to look at the aws-sdk docs.
Creating the VPC
First, let’s set up the VPC basics like we did with the last article.
With ELBs in VPC, you give them their own security group. Since this one
will accept http traffic, we should open
tcp/80 to the world.
Since the load balancer needs to talk to our web server that will get
private_security_group, we should allow incoming requests on
Launching the Instances
Now it’s time to bring up the web server inside the private subnet
Creating the Elastic Load Balancer
Finally, create the ELB. We will put it in the public subnet since it
needs to communicate to the outside world though the internet gateway.
We also specify the
elb_security_group and listener.
After we’ve created the ELB, we need to tell it about the instances that it should use. Normally, you should have servers in multiple availbility zones, but for this demonstration, we’ll just use one.
You might need to wait a bit for the DNS to propagate.
sudo dscacheutil -flushcache on OS X may help
Finally, your instance should be up and available through the ELB!
Amazon charges you per hour, so if you’re just testing and want to shut everything down, here are some clean-up steps. There’s a mess of dependencies, so you need to do it in a specific order.