From the course: AWS Certified Machine Learning - Specialty (MLS-C01) Cert Prep: 1 Data Engineering
Learn AWS CloudShell - Amazon Web Services (AWS) Tutorial
From the course: AWS Certified Machine Learning - Specialty (MLS-C01) Cert Prep: 1 Data Engineering
Learn AWS CloudShell
- [Instructor] Here we are with AWS CloudShell. You can see here from the documentation that it's a command line access to AWS resources and tools in the browser, which is really a critical aspect of it. So this means if you're at the library or if you're at a coffee shop, you can shell into here and start doing work. And it's going to be very fast because you're inside of the AWS ecosystem. So if we scroll down here and we take a look one of the things that's kind of cool about this is that you can see here the benefits. There's no extra credentials to manage because it's role-based privileges. Also, it's automatically updated with the latest operating system from Amazon. The tools are installed, there's no cost. You also get a gig of storage and you can customize it. So really in a nutshell here, here's like the visual view is that it's one of the interfaces that you can use to programmatically control the AWS platform. So let's go ahead and get started here. I'm going to go to my CloudShell environment and let's just take a look at this. How do I launch this? So I go over here, and it's just on any environment here, in any region you can launch this and you get this message here from my previous work in the CloudShell. So before we even get started I'm going to show you a little trick here which is I can delete my current work. So this is really handy because if you're doing a bunch of fancy stuff inside of your CloudShell anywhere experimenting, and you screwed everything up, well, it's good to know that you can actually delete the entire thing and it'll just restart. Okay, we're back here. AWS has reset the CloudShell environment and let's take a look at a few of the other things here in this Actions menu. So a few things that I think are really helpful is if you want to open up a new shell, you can go here, right? And now we've got a new shell. So you can open up as many of these as you want. Also, if you want to split into rows you can have a top and bottom. This can really be handy if you're working with, let's say, some kind of a foreground mode microservice like Flask or Fast API, and then you want to invoke it right below, this really, really handy interface. You can also go through here and split into columns, right? So you can build out this, really like a dashboard for doing things inside of your terminal. Now if we scroll down here as well we can see that you can download files. So that's pretty handy. If I go in here and I look at, for example, the PWD command which shows me where my path is, and I do an ls, there's nothing in here, so we'll come back to that but I could download a file if I wanted to. Now also, we can upload files. So maybe we'll start with this. You can upload one file at a time from your computer to the home directory. Your home directory is limited to one gig. So here we go. This seems like a good idea is I can upload one file, very, very common for people working with data to upload, let's say, a CSV file or some other artifact that you're going to do machine learning on. So what I'm going to do is I'm going to go to my desktop and I have a zipped file here on my desktop that I'm going to upload called cats dogs small. So let's go here and let's upload this file. We'll go ahead and select it. Here we go, cats dogs small. Perfect, and then I'll click upload. And what's really handy about this is now I'm inside of the AWS ecosystem and this is really handy because I can actually move it around places. So if I go through here and I say unzip cats and dogs, there we go. We've got this whole thing inside, which is pretty handy. If I want to, I can look inside of this directory. There we go. And we can see these different files. So let's go ahead and test out the download here since we're already here. So what I would do is I would just need to know the name of a path. So let's go ahead and download this file and let's just put in that path here. So we've got /home and cloudshell, - user, cats-dogs/ - small/Cat 0.jpg. Okay, that looks perfect. Download it, there we go. So there is actually a great feedback loop where you can go up and down into these different directories and I'll probably just remove this file as well which is always a good idea once you've uploaded it if you don't want it anymore because there's a limited amount of space. We can see this by running the df -h command. This shows us the file system. And notice here that in our home directory this is where we would actually be working with storage. And there's only 10 megabytes that are currently used, but I have another 899 megabytes available. So that's plenty to do. Many things that you'd want to do inside of the AWS CloudShell. So another thing that we can talk about here that's pretty nifty is that, notice if I type in echo $BASH, sorry, shell, it'll say /bin/bash. That's the default environment. Now what's nice about this is you can obviously edit your shell. Let's go ahead and edit our BASH shell real quick. And let's just put something kind of fun in there. And let's just say, below here, that's echo "This is BASH". Here we go, and now I'll go through here and close this environment by opening up a new tab and it'll say this is BASH, and I can close that other one. So that's pretty handy. But we don't have to just use BASH. We can also use other shells. We can also use the zsh shell, which many developers like because it has a few extra commands here. Similarly, notice how the BASH command didn't run because it's a different Shell environment. We can edit this and we can go through here and we can go to our zshrc file, and notice here that there's some really cool commands that we could play around with and we could actually tweak these, like one of my favorite ones in the zsh configuration file is to do auto cd so it doesn't need to type in the cd command, but we'll just keep things simple here. And I'll just type in echo "This is ZSH". And again, if we go through here and we go to that same thing I did before, we'll open up a new tab. There we go. This one is BASH because of the default shell that opens as BASH, but what happens if I type in zsh? This is zsh. So we have two environments here that we could play around with, but we're not done. If you're a dot-net developer you may want to use the PowerShell prompts. Here we go. If we go to PowerShell prompts you also could go through here and build out things using C# and play around inside of this interactive environment. So really pretty awesome that you can actually play around with all these different environments here. Whether you're a dot-net developer, you like BASH or you like Z shell. So let's go ahead and move on a little bit here and actually play around a little bit with using this environment to actually do some work. So what I'm going to do here is I'm going to exit again, and we can see here that if I type in echo $SHELL, we can double check what shell we're in. Okay, good, we're in the BASH shell. So the first thing that I would say that we can do here is that we could copy some files to an S3 bucket. So I'm going to go through, and I'm going to look at the official documentation here, and let's go ahead and pull this up. And this is a great place to get ideas about what you can do. So look, copy multiple files between your local machine and CloudShell, so this looks pretty cool. What we can do is we can actually upload multiple files to a bucket. So let's do this, let's go ahead and create a bucket from the command line. So first step here, I'll go through here and I'll type in this command. And so this command here says aws, use the S3 api, create a bucket, and we're going to actually put the bucket name right here. So we'll go ahead and call this something unique. We'll call this cats-dogs-11-21-2021, there we go, that looks pretty good. And let's go ahead and push Return. What's nice about this is that I don't necessarily need to use the console itself to do things. Now let's go ahead and double check to make sure that this exists. So if we go through here and I look for cats and dogs we should see if I refresh, there we go. cats-dogs, right? So we're able to programmatically create buckets and control them, which is really, really handy. Another thing you can do as well, if I type in aws s3 ls, I can pipe out the output of this to count the number of buckets. Here you can see that I have 99 buckets. So what I did is I ran the aws s3 command to list the number of buckets, pipe that into the word count -l command. And now I can see that there's 99 buckets. So, okay, what else can we do? Well, we can synchronize these files here. And in fact, if I look in this directory these are these files that I uploaded earlier. So what I can do is I can type in a synchronization command to put these inside of this bucket, cats and dogs here. So the first thing that I'll do is I'll take this name which is a neat little trick that I like to do and I will put in the hashtag right there. And that way I can refer to this command without it blowing up. And all I need to do here is just type in aws s3 sync . Which would put everything in this directory into this destination. And so this is the trick here is I want everything that's in this directory to be synchronized to the remote S3 directory. You can see here every single one of those files is synchronized very, very quickly. That's the other advantage of using this CloudShell environment. And once all these files are uploaded or synchronized into this environment what I can do as well is I can actually go through here and verify that that bucket is actually ready to go. So let's go ahead and watch this thing go here. You can see here tons of files or synchronizing and if I wanted to make small changes the synchronization command will actually keep them up to date. So really you can see how the CloudShell, if you're working with any kind of a data pipeline, data engineering, machine learning engineering, is really invaluable. So let's go back to the AWS CloudShell here. Go ahead and click Refresh, there we go. And we can see here that all those files are inside of my bucket. All right, so let's go through here and download something as well. That's a zipped file which is a common way to synchronize things. How would we do this? Well, I would just go through here and type in zip -r Cat Cat, like that, there we go. We added a zip file here, there you see this. Now all we need to do is just type in PWD and actually put in this path here. And we can actually just do this as a neat little trick, as I can do Cat.zip, that way I can verify that the path exists. This is a great idea so that you don't get yourself into trouble. So I can copy this right here, copy this path and then go here and then go to Download File.