Create and Configure an AWS EC2 Instance

Sam Julien
InstructorSam Julien

Share this video with your friends

Send Tweet
Published 2 years ago
Updated 2 years ago

Creating an EC2 instance is straightforward but there are a few things to keep in mind.

When you create an instance you have to choose its AMI (Amazon Machine Image). The AMI is the operating system and other software of your EC2 instance. When selecting make sure to pay attention to what is eligible for the free tier

After selecting your AMI you can go into your configure your instance and choose options for the network, public IP, etc. Then you choose your storage option, create tags, and configure the security group. In your security group configuration, you can create rules for your instance's traffic.

Sam Julien: [0:00] Let's walk through how to create an EC2 instance for the first time. When you get to the AWS management console, you're going to see a number of different things. You'll see these recently visited services here. You might have EC2 there already. If not, you can go under Services here at the top, and EC2 is right up at the top under Compute.

[0:19] I like to favorite the services that I use so that they also show up in this list of Favorites. I've got EC2 here as well. Let's click on EC2. If you have any EC2 instances running, you'll see them in this list here. Otherwise, we can go ahead and click on this big orange button called Launch Instances.

[0:40] EC2 instances are specific to whatever region they're in. Right now, I am in the Ohio, which is us-east-2. For our purposes, it doesn't actually matter. If you thought you had an instance running, and you don't see it on this list, it's possible that you have it in a different region. I'm going to go ahead and click on Launch Instances.

[1:01] The first option we have is the Amazon Machine Image. The Amazon Machine Image, or AMI, is basically a template that contains all of the software configuration for the instance. Like the operating system and things like that. There are a number of these.

[1:15] For our purpose, it doesn't really matter, but one that we use a lot in development is the Ubuntu Linux operating system. I'm going to go ahead and choose this Ubuntu server 20.04. One thing I want to point out is this free tier eligible box underneath the Ubuntu logo.

[1:33] You definitely want to make sure for these demos that you're using these free tier eligible AMIs. Otherwise, you're going to incur charges. I'm going to go ahead and select this image. We also get to choose our instance type.

[1:46] There are many different instance types for EC2. They vary in their CPU, and in their memory, and in their storage, and that also affects their price. For example, you might use a really powerful EC2 instance to do a bunch of machine learning computation and things like that.

[2:04] For a simple web server or something like that, you might just use one of the smaller ones. For demos, most of the time, nearly all of the time, you're going to select this T2 micro one that is already selected.

[2:16] This is just a small server with a gig of memory that does fine but isn't something you're going to use for big high-powered projects. We're actually going to leave everything as the default so we could just do this review and launch.

[2:30] I want to just walk you through some of the configuration options that you have for these EC2 servers. I'm going to click Next, Configure Instance Details. There are a number of different settings in here. One is that you can actually launch multiple instances all at once that are the exact same, which is handy. There's also these networking options as far as what network you're going to put this EC2 instance into.

[2:53] This will definitely come into play as you start setting up production projects and you need to have for example, the database in the same network as the server. Another setting you're going to use quite often is this Auto Assign Public IP.

[3:07] For this, if you're using an EC2 instance as a server, you're going to have to make it open to the rest of the Internet. You're going to likely need a public IP address for it.

[3:17] Right now the default setting for our subnet that we're in for our network that we have, which is just the default for AWS, is to go ahead and enable that. There's a number of other settings in here that you won't use probably nearly as frequently as you're just doing web servers and things like that.

[3:33] We'll go ahead and leave all of these as defaults and we'll just go ahead and scroll to the bottom. The next thing we're going to do is look at the storage that comes on the EC2 instance. You can see the fall that has an eight gig general-purpose SSD.

[3:46] If we wanted to, we could scale that up. Of course, that would also affect the price. We're just going to leave this as is, but just know that that's an option for you. You can also choose to encrypt the hard drive if you want. We're also not going to do that.

[4:00] Next, we're going to go ahead and add tags. Tags are really useful for keeping track. Otherwise, you're just going to get the auto generated EC2 instance name and that can get super confusing super quickly. I like to group my resources together.

[4:15] Let's add a tag and I'm just going to say Type. For the value, I'm just going to say Egghead EC2 demo. Next is the Security Group. I'll click into the Security Group. This is one that's going to come up quite often if you are doing a server like a node server or something like that.

[4:35] A security Group is basically a set of firewall rules that control the traffic to your instance. For example, most of the time with a web server, you're going to need access both through SSH in order to update the server and deploy code and that kind of thing.

[4:50] Then you're also going to need access through HTTP and HTTPS. Let's go ahead and create a new Security Group. I'm just going to call this Egghead Web Server and I'll just match the same in the description. Each of these rules underneath here controls the access to this EC2 instance.

[5:07] Right now you can see there's an SSH rule for Port 22, that's the port for SSH. You can see that right now, we've got access for .../. That basically means everybody can access this EC2 instance from SSH. That is definitely not what we want.

[5:24] Luckily, AWS has a very handy shortcut where you can just click this drop-down and select my IP.

[5:30] Of course, my IP address is going to look different than your IP address. We've immediately made our EC2 instance a little bit more secure by controlling who can SSH into it. We're also going to want to add a couple of extra rules for a web server. We're going to add a rule.

[5:45] We're going to click this little drop down and pick HTTP. It will go ahead and fill in Port 80 for us. This time we are going to leave it as everybody. You'll see that there's this .... Then there's also this ::/. There are two different types of IP addresses, IPv4 and IPv6.

[6:06] That's what these are. These are both the IPv4 and IPv6 ways of expressing, "Hey, just let everybody in on this port." We're going to do the same thing, creating a rule and creating one for HTTPS, which will then be on Port 443.

[6:22] We're going to let everybody in on Port 443 for HTTPS as well. Now we can just do review and launch. It's going to give us a little summary of everything that we've picked. We've left everything as the default pretty much just for a little web server.

[6:37] We've got our rules here for who can get in. We've also got our tag here down at the bottom. That's all we need to do. We'll go ahead and click Launch. The next thing we need to do is to select a key pair that we'll use to SSH into our server.

[6:54] We need a public key and a private key combination. That way when we try to log into our EC2 server from our machine, we have some extra security. You can either select an existing key pair. You can see here I've got one called Egghead EC2 Test or you can create a new key pair.

[7:12] You can also proceed without a key pair, but I would definitely not do that because then anybody who happens to be at your computer could login to your EC2 instance. I'll go ahead and create a new key pair for us. I'm going to call this Egghead EC2 Test 2.

[7:28] It's going to give us the option to download the key pair. Where you keep this key doesn't actually matter. You just need to keep it somewhere that you'll be able to access it later. I'm just going to leave mine in my downloads folder and close out this download.

[7:44] With that, we can go ahead and launch our instances. It might take a couple of seconds for the actual EC2 instance to launch, but we can go back over. We can click here and it'll load our list of EC2 instances. You can see mine is pending for now.

[8:04] I'll just wave a magic wand to fast forward here. Now you can see that it's running. If I click on our instance, you can see that we have a public IP address. Let's just do one last thing. Let's actually rename this to make it easy for us to remember which one this is.

[8:21] I'm going to click this little paper icon here, and I'm going to type in a name, Egghead EC2 Test. Click Save and now we can see it. Now we've created a perfectly good EC2 instance to be able to put a web server.