Instructor: So let's practice creating an AMI
and first, to create an AMI, we need
to create a new EC2 instance.
So let's launch an instance.
We'll use Amazon Linux 2.
We'll select this.
We'll use a T2 micro, and then I will scroll down.
We need to specify the user data,
and then I'm going to copy the code here, but everything
but the last line.
So do not copy the last line.
And the reason is we are going to create an AMI
in which we install httpd.
So an Apache web server,
but we don't want to customize the HTML file yet
because it's something we'll do
at runtime from the AMI when we actually boot from the AMI.
So let's copy everything
but the last line into the user data.
Click on "Add Storage"
So now we understand all the options for the EBS volumes
including the "Deletes on Termination" attributes.
We click on "Add Tags",
and then click on "Configure Security Group".
We can attach a security group
that's already existing from us
to the "launch-wizard-1" security group.
We'll review and launch.
And launch, and we'll use
the existing key pair, EC2 Tutorial.
So we're good to go.
Now, our instance has been launched
and I can click on "View Instances".
And now we have this new instance
in pending state for being created.
So let's give it some time to boot up
and I'll get back to you.
So the instance is running
and I have to copy the Public IPv4
and paste it in the browser.
As you can see, I went too quickly
and it says this site cannot be reached.
So it's a good way to show the errors, but as you can see
because the EC2 instance has not bootstrapped yet,
not everything is installed yet on my EC2 instance.
We're getting a connection error
but if I refresh this page, for example,
and wait a little bit, at some point
the EC2 data script will be executed
and the httpd web server will be created.
So it's always good to demonstrate
that not everything is immediate.
And this is also one of the reason we create an AMI.
So all this bootstrap time, which is going to be 20,
30 seconds for this EC2 instance, will be gone
once we create an AMI.
So here's a test page.
So because we have not customized the HTTP web page
we get this standard page
in which it say you need to now customize your websites.
But anyway, this is great.
So that means, that everything is installed
in our instance and we're good to go.
So now what we have to do is to create an AMI
from this instance, so to do so you can right click
and then we're going to do "Images and templates"
and "Create image".
And so from this image, we can say, this is our demo image.
We're going to create an AMI from our instance.
So we are good to go.
We are going to do a snapshot of our roots EBS volume
and then I will click on "Create image".
So now this AMI has been created, okay.
And now what I can do is
that I can launch an EC2 instance from this AMI.
So let's click on "Launch instances".
We can click on "My AMIs" and we need to probably
wait a little bit of time for this AMI to be created.
So as we can see from the left hand side,
if you click on "AMIs", the status
of this AMI is in pending state.
So we need to wait for it to be ready
before we can launch an instance from it.
My AMI is not available
and I can go to "Instances", launch instance, and I can go
on the left hand side, into "My AMIs" and see that, yes,
my demo image was being created.
I can select it,
use a T2 micro, configure the instance details,
and in here, I'm going to customize just a little bit
this instance, using some user data.
So what I will do is that I will copy the very first line
because it is very important.
So copy the first line, then make sure you're
on the new line and then copy the very last line.
So what this will do is that it will only
run one command when the EC2 user boots up
which is to create this index.html file
to customize the message when our instance starts.
And so, as we can see, now
we don't have to re-install HTTPD and so on
because it is already installed as part of the AMI.
So it's "Add Storage", "Add Tags".
Let's just say this, the name
of this image is "From AMI".
"Configure Security Group", we're going
to use our "launch-wizard-1" security group.
Review and launch.
Launch.
Yes, I want this key pair.
And now view our instances.
And as we can see, now, we have three instances:
one is terminated, one running, one pending.
So this is the whole power of the cloud, really,
and so this EC2 instance is pending right now.
Let's open the IPv4 address.
Let's wait for it to be in a running state.
So let's wait for the instance to be running.
And now it is in running state.
I'm going to open up the IP,
and what's going to happen is that our instance
is booting up and it's going to initialize.
But very quickly, when the,
as we can see, the test page already appears,
so that means because the Apache HTTP server
was already installed
then this appeared right away.
And if I refresh,
I just need to wait for the EC2 user to execute.
Here we go.
And now we get the "Hello World"
from the private IP of the instance.
So this really shows the power of AMI.
We went much quicker into our boot time
because the software we needed was already installed
onto our EC2 instance.
So a lot quicker.
So you can imagine how AMIs can be useful for backing
up your usual software or your security software
or firewalls or custom configurations or stuff like this.
So that's it for this lecture.
I hope you liked it.
And just before you finish this lecture,
we don't need these,
so you can take these instances
and terminate them and we're good to go.
So that's it.
I will see you in the next lecture.