Welcome back to BackSpace Academy. In this lab we're going to be getting our 2
hands on with the command-line interface. We'll be creating a Cloud 9 environment 3
and using the terminal of that Cloud 9 environment to send CLI commands to AWS. 4
We're going to issue a command that will create an s3 bucket we'll also issue 5
commands to upload an object and then delete that object and finally 6
we'll issue a command to delete the bucket and clean it all up. Ok so starting off in 7
the management console. We get to the Cloud 9 console by going to services and 8
cloud 9 and that will bring us to this landing page here. If we've already got 9
Cloud 9 environments already set up, you'll have a different screen here but 10
if you haven't used Cloud 9 before this is what you will be presented with. 11
We'll click on create environment. We'll give out our environment a name. 12
We won't worry about a description it's only optional and we'll click on next step. 13
We're going to be creating a new instance to run this Cloud 9 application on 14
and we're going to select a t2 micro instance for that., We're also going to 15
select the Amazon Linux AMI because it's got a lot of tools pre-installed on there 16
including the command-line interface. What we've also got here is a 17
cost saving settings. So if we're not using this service for whatever reason 18
instead of getting billed for that EC2 instance it will go into hibernation mode 19
and we will only be billed for the drives that are attached to that instance 20
we won't be billed for that compute capacity as such so that is a 21
very good thing. We'll leave that there so that after 30 minutes it will go into 22
hibernation. When we go back into this it will come out of hibernation if we 23
haven't used it. Click on next step and that's how easy it is to create 24
a Cloud9 environment in your default VPC and we will click on create environment now. 25
After a few minutes the EC2 instance will be launched and that Cloud 9 26
application will be running and we'll have the IDE operating within our 27
browser. Ok, so after about five minutes or so we've got our cloud 9 integrated 28
development environment up and running. On the left hand side there we can 29
see that we've got a tree view of our file structure within this ec2 instance. 30
So that's great so we can actually from there we can upload files quite easily 31
just by simply dragging and dropping them onto a form. Down on the bottom 32
there we've got a batch screen. So that's a linux terminal console and from there 33
we can start issuing commands through our EC2 instance to the AWS service and 34
in the center there we've got tabs which will allow us to view files and modify 35
those files. So that is our editor as such. Now if we want to change this, 36
yours will probably be a quite light and bright user interface I like a dark one. 37
What you can do is just go into this toolbox icon here this sprocket and 38
just click on that for the Preferences and if you scroll down and you go to 39
themes you can select. By default I think you have this flat theme which 40
will be that one there but you can change it to a darker theme and I'd like 41
this dark grey one here. If you like the dark grey you can change it to that 42
quite easily. So we just close out of that now and we will start to issue some 43
commands and see how we go. Now the first thing that we need to do is to check 44
whether the AWS command line interface tools are installed so we do AWS - - and 45
version and there we can see we've got the latest version of our CLI in there 46
so what I'll do now is I'm going to issue a command 47
and that is going to create a bucket on our on our AWS account 48
The command there is AWS for the CLI command s3 for the s3 service MB is the 49
command to make a bucket and then we do s3 colon forward slash forward slash and 50
the name of that bucket. I'm just going to give it a unique name. 51
You'll need to have a different name to this it will need to be unique for a 52
bucket, and we'll click on enter, and so there we can see that has 53
successively created a bucket for us. If we go into the s3 console we'll be 54
able to see that that bucket has been created, but before we do that how about 55
we upload a file. First off, what we'll do is, we'll upload a file to this EC2 56
instance and we're going to be doing that by going on to the the tree view here 57
and what we can do is go to file and upload local files and then all we 58
need to do is just drag and drop a file. I'm just going to drag and drop the 59
lab notes onto this onto this form and then that will upload that to this EC2 60
instance. Ok so there on the left-hand side you can see that we're uploading it 61
and very quickly it has uploaded that to our our EC2 instance. I'm just going 62
to shorten that name a little bit and just going to call it notes and that 63
will be fine. Ok what we can do now is that we can issue a command that will 64
copy that file over as an s3 object to the s3 bucket. The command we need to 65
use is the AWS s3 CP command. So AWS s3 66
CP and then the the actual file name. So it'll be notes. 67
Now remember file names are case sensitive so this has a capital n so I'm 68
putting a capital in there, .PDF and then the name of the bucket which will 69
be s3 and then that name of the bucket. 70
S3 colon forward slash forward slash and that bucket name CLI... Okay so there we go 71
AWS s3 CP the file name and then the bucket name there. Click enter and 72
there we go it's uploaded that notes.PDF to that bucket. If we go into the 73
management console for s3 we'll be able to see that uploaded object inside of 74
that bucket. Okay so we do a new tab here and just jump into the management 75
console. There we go. Iif we jump into the s3 service, have a look for that bucket 76
there it is, CLI pcoady and there we can see we've got that bucket 77
has been created our notes.PDF document is in. Everything seems fine. 78
What we'll do now is we'll clean it all up by deleting that that note.PDF 79
the command we use is a AWS s3 RM and then s3 and colon forward slash 80
forward slash and then the name of that bucket and then forward slash 81
the name of the actual file itself and enter. There we can see we've successfully 82
deleted that and if we go to this management console and if we refresh the 83
screen we can see it now the bucket is empty. So the buckets empty we can now delete it. 84
the command that we use is AWS s3 and rb to remove that bucket and then 85
simply the name of that bucket. Okay so it's removed that bucket 86
that's pretty well all I want to show you as far as the command line interface goes 87
because it's a very, very powerful tool that can be used with a whole heap of 88
different services. If you want to know more about the CLI or you want to 89
see the documentation just go to the Amazon website so aws.amazon.com/CLI 90
and then we can go to the CLI reference. Okay so that will have a whole 91
heap of different commands that are available for the different services 92
you see the available services is absolutely massive. Ee'll scroll down 93
to what we've been using, which is s3. We see there we've got two we've got s3 94
and we've got s3 API. The s3 API is far more powerful and that takes 95
advantage of all of the API commands that are available whereas the s3 96
commands only have very shortened limited use, so they're they're more for 97
quick things to be done, so CP instead of copy and then having this big long string 98
Let's have a look at that so we go into the s3 API and if we want 99
to create a bucket we can scroll down and we can see the command there it's 100
quite long and lengthy, so we can see there it's a lot more verby than using 101
just a simple CP command but it's a lot more powerful, you can do a lot more with it 102
I'll just go back and we'll have a look the s3 commands so we can see here 103
we don't have a lot of commands available so they're the only commands 104
that are available using their s3. If you want more than that and you want the 105
full capability that you have with the s3 service you can use the s3 API commands 106
Let's have a look at one of the ones that we've been using there 107
CP and we can see there it's going to have different options and whatever that 108
are available it'll have an example we scroll down. Ok so there we can see 109
we've got an example. Now what you do there is that we've got first off we define what 110
that file, that local file, is and then we define where we want to send it to 111
so we just sent it to my bucket but if you wanted to change the name of that 112
because you can see here we're going from test to test2 can actually put 113
that extension to that bucket name there. So that's pretty well it, as far as that 114
S3 stuff goes, it's not really a lot to learn with that s3 but again go to the 115
document page and have a look at it and see if we can play around with some of 116
these different sorts of commands and you'll find it is quite a powerful thing to use 117
so that brings us to the end of the lab first thing that we need to do 118
now is just clean up this development environment so what we do is, we click on 119
AWS Cloud 9 here. We go to our dashboard and there are our environments 120
now I've got two environments here you'll just have one, select that 121
environment and delete and just type in delete and that will eventually delete 122
that ec2 instance and that complete environment and bring you back 123
so that you're not going to get a bill at the end of the month. That brings us to the 124
end and I look forward to seeing you in the next one