In this video, Jeff Winesett demonstrates creating an Amazon machine image, AMI, from an existing EC2 instance, and then launching a new EC2 instance from this AMI.
- [Instructor] The next step I wanna take is to create an AMI from the web server so I can use that image to create other identical web servers. So again from the console, let me go to the EC2 service. And I just go into the instances that I'm interested in taking an AMI of, in this case we just have one, it's already selected. And I can go into the Actions drop-down, and Create Image. The first thing I need to do is create a name for this image This an be anything that you like.
I like to keep some versioning convention directly in the name so I can quickly see the latest versions. Let me go ahead and use test-web-server, and I'll call it explicitly version-1.0, our first version. Provide a brief description, LAMP web server, and I do have the option to have the image created without rebooting the instance.
But if at all possible, allow the instance to reboot when making the image, it will ensure a more consistent snapshot. The tool tip says as much as well. So let me not specify No Reboot. I don't need to add any other volumes or do anything else when creating this image, so I'm good. I'll just click Create Image, and it kicks off the process. Now it's creating an image of the web server. I can check on the status by going into the AMI section. So here I'm back on the Instances section, but if I look over here on the left-hand, I can go to AMIs, and I can see that it's currently actively creating that image, and I've got a status of Pending.
Similar to the instances and the RDS instances, I've got some tabs to give me some more information about AMIs, the details, the permission set, any tags that I happen to have specified. And, I do need to wait for this image to be in an available status before I can use it, and it can take some time to create. Okay, now the AMI is available and ready to use. Right now, I have only one web server in one availability zone behind the load balancer. I need at least a second one in a separate availability zone to achieve my high availability requirements.
I can use this newly-created AMI to create a new web server and launch it in a separate availability zone. Before doing so, I'm gonna check two things. First, I'm gonna check which availability zone the current instance is already in, and then I'm gonna remind myself into which two availability zones I configured the load balancer to do the balancing. I wanna add this new instance to the load balancer, and it will make things easier if it's already in the appropriate zone that the load balancer is balancing to.
So first off, let's check which availability zone the current instance is already in. Go to Instances, click the one that you are interested in, we only have one, go to the Description tab, and I see that it's in Availability Zone us-west-2a. So Zone A. Next, I wanna check on the load balancer. So I just toggle over here to the left-hand menu, Load Balancers, Description, and Availability Zones down here. I see that it's been balancing between both A and B.
So great, this tells me that I really need to launch a new instance into Zone B in order to get my high availability dual availability zone load balancing happening. Okay, so let's launch a new instance into Zone B. Go back over to the AMIs, here's the one that I just created it's already selected because I only have one. I'm gonna click Actions, and Launch. In this case, it's the same as the steps that we just took to launch the new instance, except we've skipped over the step of choosing the AMI because I've already specified the AMI.
So I'll stick with the micro-instance type, the details are mostly the same, I don't need to do anything except that I want to make sure that I submit it into Zone B. The rest of this stuff looks good. Advance Details, don't need anything here because all of that information that we added to the initial instance is already baked into this one because I'm creating this instance from the AMI, which was an image based on the previous instance.
Okay. Next I'll add storage, nothing really to do here. Next I'll add tags, name, we'll call it web-server-2 for kicks, environment, see, now it already remembers the previous ones that I have, that's helpful. Test, and I'll add another tag, cost-center, great it's already there for me. Helps me remember the names of the tags before so I'm consistent with using them.
And marketing. And I can use that friendly tool tip there as well. Security group, again, I'm gonna be launching this into the web tier, so I wanna choose my web tier security group that we've already created. Looks good. Review the details, and launch this thing. Once again, it's gonna ask me about the key pair. I wanna use the same one that I've already created, so I'll choose that and move onto launching the instance.
Great, it's been launched. We can check out the details right here. We see that it's in a Pending state, and once again we'll need this to be in a fully available state before we can use it. Okay, great, now that the instance is available I can add it to the load balancer. The load balancer is already configured to send traffic to a target group, so I need to edit the target group and add this new instance as a registered target for traffic in the group. I do that over here on the left-hand menu, go to Target Groups and get rid of whatever might be in the filter from the previous screen.
I see that we've only got one target group created, that makes sense, and I go down to Targets. I edit the targets, and I can choose to add instances into the target group. This one's already added, i-013ef6d. I wanna add the new one in Zone B. Add to Registered, and save. Now I see this new instance as listed under the registered instances here, and currently it's in the status of Initializing, so the target registration is still in process, and we have to wait for this to complete before it's available for use.
Can refresh, okay, that didn't take too long. The status is healthy, and now the load balancer should be balancing traffic equally across both of these instances. So let me confirm. Let me toggle back over to the tab where we were already viewing with our one instance that was being hit from the load balancer. If you recall, this URL is taken from the DNS entry from the load balancer. So before we'd only had one instance behind the load balancer, and we only saw one instance ID being shown.
Now, since by default the load balancer is configured to send traffic in a round-robin method to each server kind of equally, meaning the first request will go to Server A, the second request will go to Server B, the third request will go to Server A, and so forth. So I'd expect to see the Server Instance ID change with every request as each request is being balanced between the two servers. So let me demonstrate. If I click Refresh, I get i-013ef6.
If I click Refresh again, I get a different ID, i-0abdd, and sure enough that is our other instance. So as we can see, as we're hitting the load balancer it's balancing traffic between these two instances and two availability zones, exactly what I wanted. The last thing that I need to do for this application setup is to set up auto scaling. Auto scaling will provide automatic horizontal scaling both in and out of the web server tier, which is a big part of taking advantage of the elastic nature of the Cloud.
I'm gonna do that next.
- Benefits of cloud services
- Making architectures scalable
- Examining cloud constraints
- Virtual servers, EC2, and Elastic IP
- Using the Amazon machine image
- Elastic load balancing
- Using CloudWatch for monitoring
- Security Models
- Elastic block storage
- S3, CloudFront, and Elastic Beanstalk
- Handling queues, workflows, and notifications
- Caching options and services
- Identity and access management
- Creating a custom server image
- Application deployment strategies
- Serverless architectures