hi my name is noah gift and today i'm going to talk to you about
how to provision aws ec2 instances what are all the key components of aws instances
some of these components can be confusing because there's many different moving parts
and also how do you actually launch it using more than one method for example using an api
call or using the chameleon utility then finally how do you launch a spot instance versus launch
a regular on-demand instance okay let's go ahead and get into the details
all right let's talk through the key components involved in provisioning amazon ec2 instances
there's actually a lot of detail that is easy to gloss over first up on the left
here we have this concept of a security group and this is the firewall for your instance
it is where you explicitly control the input and the output to your machine or even other security
groups that you'd like to communicate with the key pair would be the ssh key that you would use to
ssh into that instance you would also need to have port 22 available from the security group as well
the amazon machine image or ami is a amazon image that it typically is prepared for you
through a quick start for example amazon linux 2 or windows or os 10 but there also are
community images or your own images the instance type these would be the kind of ec2 instances
you'd like to launch maybe a cpu heavy or a memory heavy or gpu heavy and then there's also
the concept of on-demand which is the the typical way that most people launch or their spot which
can save you up to 90 and it's one of the reasons why i like spot instances so much vpc this is the
virtual private cloud this allows you to isolate everything that you're doing inside of really a
virtual network and you can explicitly control who and what are talking to machines and then iem roll
this is the level of privileges you'd like your ec2 instance to be able to have for example if
you want your ec2 instance to talk to s3 you would actually give it those privileges in the iem role
now the launch method this is also something that is often not known is that you can obviously
launch your ec2 instance from the the gui or the terminal here but you also can launch it from
the console and the sdk and the cli so you really you have multiple methods to launch instances and
we're going to go through all of those different methods okay let's go ahead and get started here
and get into aws and we see the console right this is really where most people start off
but one thing i'll start off with is showing you that ec2 here is in my recently visited
and i can see that there's one instance that's running now if i want to launch a new instance
fairly straightforward i can just scroll down here and click on launch instance and when i
go ahead and i say launch instance i could tag it if i wanted to maybe i would call this web
and if i scroll down here notice that this quick start menu is really a good place to start amazon
linux is how most people would probably initially get started there's also ubuntu there's windows
there's there's red hat right there's lots of different types of machines here including os 10
if you're doing let's say swift development and then once i go through here and i select let's
say amazon linux i would scroll down here and it would ask me to select the type uh micro could be
one instance or i could scroll all the way down to some you know really large instance type here
i could even compare instances if i wanted to set up a key pair login that would allow me to
log in via ssh how would i do this well i would actually go through here and say create new key
pair then go ahead and call this demo video and then i would select which format so openssh is
typically from linux to linux and this would be for putty if you're using a windows machine
if i go through here and i create this key pair it then fills in those values for me
uh finally the network settings this is where i would configure my security group or firewall
rules and and typically if you do want to connect initially with ssh you're going to have to figure
out where you want that to come from uh to start out with zero zero zero is going to let anybody
from the whole world be able to attempt to connect of course they can't connect without
the dot pim file and if i scroll down here this would be where i would configure the storage and
there also are some advanced options as well and you also could go through here and configure the
number of instances and if i scroll down here i would actually go ahead and launch now one thing i
will compare here though is under advanced details notice that you also could request a spot instance
and this would actually save you significantly on the cost and a couple of the things that you
could do that might be helpful is you could also add elastic inference this would be gpu
based inference you also could select where you'd like it to be in the cloud you also could
go through here and add user data as well this is one of the things that is is very interesting is
that if we click it you click on user data these are commands that you can actually specify so for
example user data for linux so if we go ahead and we take a look at this what does this do well you
could actually install software on boot and here's a good example of a script that someone could
install and so you would go through here and install apache on this machine even before it
starts up and so that's really the purpose of the user data scripts and you can also call this from
the uh the api as well so assuming we want to do all the stuff let's go ahead and launch an
instance it's going to go through here and do this whole launch and you can notice here it's actually
been able to make that request and now it's in a pending state so this is another
important thing to be aware of is that there are several kinds of states and if we go ahead
and take off this instance id here you can see that the instant states are pending running
stopped and in particular or there's terminating as well and in particular here the pending state
just means that it hasn't fully launched yet now i do want to point out that there's another way
to control machines and if we go over to aws cloud shell which is uh really this icon right here
a couple things to point out here that are kind of fun is that i could actually go through and launch
a new instance by just using aws commands if i go through here and i type in aws ec2
run instances dash dash image id all i need to do is actually specify the
emi that i that i want to launch with and so how would i find that ami well if i go back here
and i go to emi catalog all i would need to do is scroll down here and find an ami that i'd like
to launch so let's say i want to go through here until i find windows here we go i want to launch
let's say microsoft windows server 2019 base i would go ahead and grab this ami
id and then i would go back to my terminal here and i would paste it in so this would work for any
ami that you're launching we go ahead and do that
and notice it does the request and it goes through and by default it'll it'll pick uh the
the small or the micro instances unless i specify specifically the type which is a
flag and once i've done this this will go through and make the request and i can actually go back
to the instances here and look there's another one pending right so it shows up right here so
you can launch it from an sdk you can launch it from the cli and you can also launch it
from the terminal now notice that this particular instance that i had launched earlier is ready to
go so let's go ahead and click on that instance id here and now how would i connect to this well
fortunately you can connect to it right from the ui here and in fact this instance connect will
allow you to do that and if we go through here you can see right from the browser i'm able to log
into my instance and and say for example uptime you can see it's only been up for one minute uh
if i want to launch a different kind of machine let's go back here and let's look at instances and
if we scroll down here we can see that there are other machines that are actually running as well
and i think this is the one that has already been running for a while and if i click on this i can
scroll down here and i can look at the information about this machine and we see that this is a
windows machine as well how would i connect to this well same thing i go ahead and i say connect
and it says we won't be able to connect to your instance common reasons because
the ssm agent isn't installed on the client so a different way that we could actually connect is by
using the rdp client and in order to connect via the rdp client one of the things that you could do
is you could download the remote desktop file and also you would need to go into your security group
and actually open up this port and then at that point i would be able to connect remotely via
that instance and control it so now that we know how to launch and specify the kinds of
instances we launch from the terminal or from the console the really the last step here would be to
do from the terminal a command that would describe for example all the instances that are available
and if i go through here and i say ews ect described instances filter
uh and we don't have to actually do a filter we could just say describe all the instances
it would go through here and it would tell me every single instance that's actually running
and what i could do at this point is i could terminate any instance so how would i do this
well i would go through here and i would run the command aws ec2 terminate instances
dash instance ids and i could just scroll back to let's say this micro instance go find its id
and actually terminate it from the terminal as well there we go you can see that i've been able
to terminate that instance now that's not the only way to terminate if we go back to our console here
anything that's still running if we go ahead and refresh this we can see that these are
still running that i could also go through here and say actions and control the instance as well
so we could say for example manage instance state and we could say i want to terminate
these instances and that's another way to control the instances so there are many different ways to
interact with this ecosystem including the terminal including the console and if we go
back to this diagram right here and take a look at it you know a few key takeaways are that we
were able to touch on all of these different methods from the security group the firewall
rules the key pair this is the ssh connection the emi this is the kind of machine the instance type
the on-demand versus spot the virtual private cloud which is controlling who can talk to what
the privileges for for the ability to talk to other parts of aws also the launch method uh
in this case we used more than one the user data what you could put in when it launches and then
the kind of storage you'd like so really this is a good overview of how to get started with ec2