In this lesson we're going to create a new ec2 instance on Amazon Web Services.
An ec2 instance is simply a virtual server that runs on AWS that hosts our
application. We're going to be creating this server in the AWS console, we're
going to assign a public key to the server so we can access it using SSH and
we're going to allow HTTP access to the server so we can access our API once
installed and up and running so let's get started. Start by making sure you're
logged in to the AWS console. I provided a link to the console in the resources
of this video. Once you're logged into the console you should see a page
similar to this. It has options for all the different AWS products that they
offer. The one we're going to be using is this ec2 one under compute so if you
click on that it will take you to the ec2 dashboard page. Before we create our
server we need to assign our public key to our AWS account so that we can login
to the server using SSH once it's up and running. We're going to use the same
authentication method that we added to Github in the previous video. The way
this works is we add our public key to our AWS account and then when AWS
creates our server it automatically assigns the public key to the server it
creates. So on the left hand side of the ec2 dashboard scroll down and find the
key pairs option. Click on the key pairs option and we're going to import a key
pair. It's asking us for the public key contents. This is the contents of our
public key file that we used earlier when we added it to Github. So if you
don't already have it open load up the terminal window and type atom squiggly
line, which means the home directory /.ssh/id_rsa.pub
this will open our public key in Atom editor. Once it
opens copy the contents of the key and then head back over to the AWS console
and paste the public key contents in there. We need to give it a name so let's
just call it whatever name you want so I'm going to call it mark-desktop you
might want to use your name or your desktop name or whatever computer this
key is for. Once you've type that you can click on import. Alright so now our key
is imported into AWS we can go ahead and create our server. On the left hand side
here scroll up and click on the ec2 dashboard option at the top. Then click
on launch instance here to create a new ec2 instance. We've got various options
of operating systems we want to use for our AWS server. We want to find the
Ubuntu server 16.04 LTS version. You can see here it said
that it's free tier eligible. That means that while you're in the free tier which
is for the first two years of signing up to AWS you can use this
server at no cost. So as long as you only create one of these servers you won't be
charged for it until the free tier period ends. So next to this Ubuntu server
16.04 operating system, click on select and then it's going to ask us
what type of instance we want to create. Again we want to choose one that is within
the free tier eligible option. That is this t2 micro instance. A t2 micro instance has
one virtual CPU and one gigabyte of memory. This should be plenty to test and
play around with our API. Alright so make sure that one selected and click on
review and launch. Finally it's asking us to review the
server that we want to create so we can leave all of this default and then click
on launch. Now it asks us if we want to assign a key pair to our server, we want to
make sure the one that we added earlier so in my case mark-desktop is
selected and then just click on I acknowledge that I have access to the
selected private key and then click launch instance. Ok so now our instance
will be created in AWS. This can take a few minutes so while we're waiting for
that to happen let's create a new security group that allows HTTP access
into our virtual machine. So if you click on services again you go back to ec2 on
the left hand side we should have an option for security groups. Click on
the security groups option and then click on create security group. We're
going to call the security group allow HTTP access inbound.
This means allow HTTP access into our server so we'll give it a description
allows HTTP access to our server and then on the inbound make sure you have
the inbound tab selected click on add rule. On the type you want to select HTTP
there it is. Alright it automatically chooses port 80 and it
allows access to all IP addresses to our server on port 80. That's what this 0 0 0 means.
Alright so now we can create this rule, click on create and
then head back to the ec2 dashboard. Click on the running instances option
and we'll see if our server has been created yet. Alright so we can see that
the server is running, we need to assign our new security group to our newly
created server so click on actions here and then click on
networking and click on change security group. You want to check the allow HTTP
access inbound option and then click on assign security group. Alright so now that our
server has been created let's go ahead and connect to it. So if you click make
sure the server that we just created is selected here and click on connect. This
will give us the details that we need to connect to the server on AWS. So we don't
really need any of this other information all we need is this line
here so the DNS or the Public DNS address for our server. So copy that and
then head over to the terminal window, now type SSH and then paste the DNS name
of our server and hit enter. Type yes. This just accepts the fingerprint and
you need to do this the first time that you connect to any server. Okay so we got
permission key denied and that's because we need to specify the username that we
want to log in as. So again if you push the up arrow to get the same command
that we just entered and in front of the DNS name type the username ubuntu @
this says login with the user Ubuntu on this address and enter again.
You can see this time it has connected us to the server. We can tell we're on the
server because this part of the terminal window has changed to the hostname of
the server. Okay so that's how you create and
connect to a server on AWS. Thank you so much for watching, I hope you found this
useful and I'll see you in the next lesson.