In this video,
you'll learn about some common AW S C L I commands that you can use to interact
with aws.
Our plan is to go over frequently used AWS C l I commands that replicated what
you did in the web console. During the lab exercises,
you'll run each command and learn about their use cases.
So like I said,
I've chosen 10 commands that replicate what you did in the AWS web console.
I have thrown in a few xs for good measures so you can get some more exposure as
well.
I'm not gonna go over each of these 10 here as we're gonna explore them more in
the terminal in a bit, but please take a,
a second to pause the video and go ahead and look at each and understand, uh,
get yourself a good idea of what we're gonna be going over. Okay,
let's get started.
We are going to go ahead and run these commands from our local host instead of
the C two instance that we created earlier. And this is because if you remember,
when we set up a lab, we set up the AWS command,
our access key and secret key on our local host.
And instead of duplicating that on the e c two instance, just easier,
if we were run the commands from there, there's, there'll be no difference.
So to go ahead. Okay,
so I'm gonna go ahead and exit out of my SSA session. You can just type in exit,
hit return. And here I am back in my local host.
I am in the lab terraform sub directory.
It doesn't matter which directory in to run these commands. Okay,
so if you remember when we first set up our lab,
we used Terraform to create our infrastructure and explore data and the AWS
console, you could do all those things we did in the browser.
And Terraform actually using just the S C L I. Like I said before,
I've cherry picked some common commands that you can use to manage your AW s
resources. So let's go ahead and look at the first command and we're gonna fetch
information about BPC since that was the first major thing that we discussed and
talked about when we were creating Terraform. Makes sense that we, we,
we look at that here now.
So we're gonna describe VPCs and so when we use the the describe VPCs command,
um,
you're gonna get all the VPCs in the account and then after that we'll learn how
to filter down. Uh, one,
one quick thing about all these AWS commands we're gonna run.
They show the output in J S O N by default for us. Um,
there's nothing wrong with the J S O output. Um, you can also do table, um,
which will show it more of like a table view.
I think the table view looks a little bit nicer on video here.
So that's what we're gonna do. And so basically we're gonna, uh,
append the dash dash output table flag to each of these commands.
But I just wanted to let you know, let's,
you could exclude the output table and just get json, okay,
so we'll use the AWS command, we're gonna use EC two.
And here's our output table.
And we're gonna describe our VPCs. And like I said,
this is gonna show us all the VPCs, which means there's obviously,
there's two of 'em.
There's the default one and then the lab VPC won't create it.
So lemme hit return. And here we are,
we have this nice table output. Um, and as you can see,
it gives us the first VPC up here, which
is the 10 0 0 slash 16,
which we know that is our um, vpc.
And you can see down here it has a name and that's the lab vpc.
But then you can see we're in this less style, uh,
output where you just have the colon and the blink and flasher.
If I hit the space bar here,
I can go all the way down to its final and then we hear end.
And if we wanna get out here, we can hit q. The other sider block here,
you could tell is our default VPC that was created for us when we created our
account. So I can hit the up arrow and I can grow up,
up and down using the arrows just like I couldn't less.
And so there's both of them. So let me hit Q to get out of there.
Okay, so now it's just filtered down.
Let's say we wanna look for the specific thing. I'm gonna hit the up arrow,
right? And then I'm gonna use the dash filters. The dash filters.
SA uh, flag and filters takes a name and a value. And,
and in our case, our name here right is gonna be the tag name.
So this is a little bit confusing. Let me just type it out and you can see. So
the tag, when we created the tags,
remember we had a key value in the tag and the key was name as well
and the value was the name, which in our case is live vpc. So here
the filters needs a name in values and in our case it's gonna be lab
vpc. So I'll um, as you can see,
so we're filtering on the tag name and then the value we're looking for is lab
vpc. So this should only give us the one VPC output. And here you go.
As you can see, we don't have the extra long output.
It's the one VPC that we created and we know it's R one cuz we can see down here
is the tag and it's lab vpc. All right,
let me hit Q to get out of there. Let me clear the screen.
Okay, so we can continue going down the line.
And let's look at our subnets.
So EC two sub command and then we're gonna describe our subnets.
I gotta spell describe first and
let's do the output table.
And so we should get all the subnets.
Now there was quite a bit subnets if you recall.
We only created one for our test lab. But as you, so here we are,
here we have our subnets.
The first one up here you can see is that it's in the US west two
a availability zone. Um,
it is the 10 0 1 0 slash 24,
which happens to be our subnet that we created.
And you can see the tag here is lab subnet public one.
And if I hit the space bar, we'll page down, we'll get the next subnet.
And as you can see here, we can just keep going down here.
And as you can see, as we keep scrolling down,
these are all the different subnets uh, that was created when we we signed up.
So if we wanted to, you could use the same
dash filters, you could use the,
the same uh, thing we did with uh,
the VPCs using the filters and then go on name and the lab subnet public one
to grab that specific one. But I won't show that way again,
you cuz we already just did it for the vpc. Let me clear the screen.
Okay, the next command that we're gonna go look at is security groups.
And to make this easy, I'm just gonna hit the up arrow.
And this one is describe secure IT key
groups. And as you can see, if you remember,
we had multiple security groups, but it turns out in our, our table output here,
if you recall the uh, the name the,
the description of our secured group that we created was allow s ssh and H E B
inbound traffic. And it has the front port, which is the 22.
And you could see that. And then if we keep going down here, um,
you also have the 80 front port TCP two port 80.
And then here we are getting into another subgroup here is uh,
this is the default VPC security subgroup, which is right here. We keep, uh,
hitting the space bar attack go down so we reach the end. So um,
we can hit Q to get out. And so that was viewing the security groups.
And as you see we have all the key values that we saw in the content pain on
the detailed pan up. We were in AWS web console. Uh, let me clear the screen.
So the next thing we wanna move on to is if you remember when Terraform to
create our key pair,
we actually used a file to create a key pair and we use Terraform to copy that
up so we could SSH onto our Amazon Lennox host because by default there's no
password for the E C two user. It's only Keybase for security reasons.
So one way you could do is if you needed to grab
the key pair, the public key pair you, you created,
you can actually see them all here.
Not the actual keys of course itself because the uh, thing,
but you can actually see the key pair ID where they're stored. So if we do this,
and if you notice here, I didn't use the output table,
I just wanted to show you what the J S O looked like one time.
And this isn't a lot of output so this was a good one to show you json.
But you could see here we have a key pair ID
and you could use that if you were ever creating a new instance from the AW cli,
you could use that key id. You have the name, whatever type it is,
there's no tags on it. And then when it was created.
So to get out of this JS o I'll put you Q
Okay, so let's move on to our next set of, of commands.
And these are all gonna be based on describe instances,
our C two instances.
And this is where we're gonna learn more about the help command for each of
these commands. So AWS E C two
describe instances and let me add my table output here and
let me put my output table here and may make sure I spell everything correctly.
And let's go ahead and run this command.
So I've only created one instance here for those, for these courses.
And so only one should show up. But here is our table output.
You can see here is our instance ID and
I'm gonna copy that into my buffer cause I'm gonna show you one way you could do
this as well. So I'm just gonna copy the instance id,
you can see that it is a T micro. We launched it with our key pier,
which we just saw.
And then you have the public IP address of this e c two host and also the
private and all the C two instance metadata that we saw.
This is all about the rest of the metadata that you see in that pain.
You keep hitting the space bar to tap down, you'll get more and more.
You can see the security group that it was attached to what association it has,
uh, network interfaces and we've reached the end and obviously the tag and you
remember this tag lab one and then environment, it was lab.
So hit cue to get out of here. And so interestingly enough,
each of the commands that you run, you can tag on help to the end.
And what this will do,
this will drop you into like it's a man page for that command.
And so if I hit return, you can see here we get to the describe instances,
uh,
man page and it basically tells you it describes the specified instances for all
or all instances.
So you could do a specific one or all of them and we just did the all command.
So let's figure out how to, uh,
go through and just figure out how to grab just one specific instance.
So if you hit the space bar again,
it will page down and the first page down as you see,
you can see here it has the dash dash instance IDs and it takes a value.
So that is what we're gonna use.
That's the flag we're gonna pass to this command to just get our specific
instance id. Uh, if you come down here,
it tells you what each of these different um, things are.
If you can see here instance ID is the ID of the instance and it basically just
gives you a thing and we could keep hitting space bar.
There is tons of information in here. Also, there's a dry run,
there is a,
tells you about the J S O syntax output tells you about the paging size,
tells you about the different output formats is JSON tech's table.
And the amel obviously we've been using the table is debug option.
I won't go through every single uh, option here in the major,
but just just to know if you're unsure of what flags to pass the command or
you're unsure about a command itself, the help here for AW C L I is fantastic.
So all right, let's hit Q to get outta here.
And so what we're gonna do is we're gonna use the dash dash instance IDs.
Okay,
lemme clear the screen here and we're gonna hit the up arrow just to make it
easier. And then we're gonna do dash,
dash instance IDs and then we're gonna paste in the instance id we took from the
describe instance command we ran just earlier.
And so now this should output just that instance. Id, uh,
just that instance running now we've only got one running,
so the output's not gonna really change, but you,
I wanna show you that you can use different flags and use the help menu to
figure out how to dwindle down your results. And as you see here,
we go ahead and we get the same exact output.
I won't go through it all cuz it's the exact same we saw earlier,
but this time we showed that we only fetch the specific one.
All right, so let me go ahead and clear the screen right here.
And so we're gonna stick with the EC two instance ones, right?
And if we do just the help command rate here,
we can go ahead and instead we don't know the, uh, sub command we want to do.
And now this gives us all the sub commands for e ec two part
and just like we had, unless you could do slash and search for this,
now we wanna run an instance, right? So we've, we've looked at 'em,
the Terraform and a s console, remember you can create it through that,
but you can run an instance from a s uh c L I as well.
And so I'm gonna hit slash run and hit return.
I'm gonna hit end to keep searching and as you can see,
there's quite a bit until we get to run dash instances and that's exactly the
one we want. So I need to learn more about that. I can hit the queue.
And then what we wanna do is we want to go run instances help.
And then now, now it should show us what we can do with the run instances.
And here it says is launch a specified number of instances using an AMI for
which you have permission.
So this basically is gonna do everything Terraform did for us on create the EC
two instance that you can use the launch instance button from the e c two web
console. Now obviously launching an C two instance,
there's so many different flags you could use. So I'm not gonna go into it.
We're actually not gonna run this, this command. Um,
and the reason being is because if something happens,
you'll have another instance running.
I don't want you to have to deal with any of those problems. So, but I am gonna,
I'll pace the command to show what it looks like,
but these are all the different flags that you can use.
So I'm gonna quit outta here and then I'll go ahead and, um,
through the screen and I'll go ahead and uh,
paste what the command you would use to run the instance and then we can talk
about it. All right, so there we go.
So there is the a c two run instance command, as you see with the flags,
it requires an image id and that is the,
basically the AMI that we've used in our case.
Remember we used Amazon Lennox two, we could see that we want to count of one,
we only wanna spin up one of them.
We select the instance type here it's the T2 micro, which is the free tier.
And then here's the key name. And if you remember we used the key name,
which was the lab key pair that we used, that we created for ourselves.
We also see here that we set the security group IDs and you saw
when we did the describe security groups command that there was the ID
security group ID for us that we could, uh,
substitute there or we could use these variables if we wanted to as well.
You could see building a BA script out of this and setting these variables
ahead. And then running these, uh, aw C L I commands after you, you, uh,
create these variables.
And then finally you need the subnet ID for what subnet you're putting it into.
And this case would've been the, the one that we created. And we get the IDs,
notice that we're using IDs here and not names.
And and that's for specific reason and that's why you get those unique long, uh,
characters of the IDs when we created stuff and when we reviewed them in the AWS
web console. Okay, that was a lot. So I hope that makes sense to you.
I'm gonna go ahead and control C outta this.
If you wanted to terminate an instance, which is the,
obviously the opposite of running it, you
can use the terminate instances command. Make sure I spelled that right. It did.
And then what you would use is you would use instance
IDs again and then you would paste the ID
of your instance ID that you wanted to terminate.
So obviously we're not gonna terminate ours yet when obviously when the course
is over, feel free to, to disable your whole account. Like I've,
I've told you before,
or you could go ahead and run the terraform destroy command,
um, that we talked about also in the,
the lab video where it'll take down all the stuff you've created and then that
way you have an empty account.
You don't have to worry about occurring any extra cost just in case.
So I'm a control C outta here. That's how you terminate instances,
that's how you run an instances, that's how you look for instances. Okay,
so lemme clear the screen. The next command that we're gonna talk about is, uh,
something that we didn't do actually in the web console,
but I added this because I think it's important because in a real production
environment we would've created users in groups along those lines.
So we're gonna talk about using the IAM resource and
we'll talk about creating and deleting and listing users.
So the first thing we're gonna do is, well, let's,
let's just list all the users that are on our account.
And as you can see, I did the J S O output here. It's empty users,
an empty array here. And that is because
I'd never created a user. When we set this up a terraform,
we were using the default user just for simplicity.
So let me hit Q to get out of here. Okay, so what we're gonna do,
and we're gonna use the, lemme do the output
table here and we're gonna use the create user sub command.
And the flag it takes is username.
And I'm gonna just create a user called Bender. It's not that big a,
you can name it whatever you want. Uh, we're only gonna create it,
we're gonna delete it obviously right afterwards too,
so you don't have any leftover users, but there you go.
So I go ahead and hit return and it tells me it created a user,
it gives me the id, tells me when it was created, and there's an arn,
which we won't go into now, so oh that's great. So we hit Q to get outta here.
So we have this user.
So if I hit the up arrow with Weis to get the list users again,
but this case I am going to
use the dash dash output table.
And you can see now when I list users, it has our vendor username.
Now Bender doesn't have any policies or any kind of permissions or anything
anyway, can't really do anything.
But I wanna show you how easy it is to create a an IM user inside aws.
So now what we're gonna do is I'm going to
scroll up and instead of the create user, I'm gonna get rid of the create.
And you see how he this, we're just gonna say delete user.
So now we're actually gonna delete the vendor user and get rid of it.
So I go ahead and hit enter here. We have no, uh,
output back means that we're successful deleting it and to prove that it's gone,
we can use the list users command,
hit up arrow a few times to get the list users and you can run list users again.
And as you see now we're in the table format. There is nothing there,
it's just empty, but just the header. Okay, so we,
we've covered some common AWS C L I command,
so that iselle we're gonna discuss here in the terminal.
Let's head back over and we'll do a full recap. Okay,
so let's talk about what we did. In this video.
You learned about 10 common AWS C I commands that you can use every day.
You practice finding information about some of the commands using the built-in
help. And finally, we executed each command and navigated the output. Now,
while you can create the infrastructure with AWS C L I,
I would hesitate and say that you should still stick with Terraform or the other
infrastructure's code tooling, like we talked about earlier on,
for making sure that you have item potency and that if there's any other issues
like the AWS C L I changes,
you don't run into issues there and you wanted to keep it consistent.
But I wanted to show you that you can do all these things that we did in the web
console and in Terraform using the fantastic AW S C L I that Amazon
provides. This brings Section seven to a close.
In this section you learned about some frequently used commands that you can use
in your terminal to interact with Lennox and aws. In the next section,
we'll wrap up this course with some best practices for the cloud and discuss
where you can go next to keep on learning. See you soon.