Hello, and welcome back to CS615 System Administration. As you know, we'll be using the command-line interface to Amazon Web Services exclusively for all our work in this class, and so I wanted to show you a few quick ways to save yourself some typing. As I'm fond of noting, System Administrators are notoriously lazy and want to avoid having to repeat anything if we don't have. To this end, I'll show you how to set up a few shell aliases and functions to work with the aws command-line tools. Let's go! So we'll rather frequently have a need to spin up a new AWS instance, and to do that, we'd have to run the aws ec2 run-instances command and specify the AMI ID. But now I happen to use a different key pair for all my AWS instances for this class, so I also have to specify "--key-name stevens" for every instance I create. That's a lot of characters to type, so let's create a shell _alias_ for this. With this, we can now simply type 'instance' followed by the AMI ID. But I also want all my instances to be full dual-stack IPv4/IPV6 enabled. Unfortunately, AWS does not enable this by default, and you need to configure a subnet and security group appropriately. I have a blog post linked at the end of the slides here, and if you follow that, you end up with a security group and a subnet with a tag 'dualstack'. So I can wrap the command to launch an instance using that subnet via this shell function 'startInstance'. This function grabs the subnet-id and security-group-id from the tag, the runs the 'instance' alias with those parameters so that you just have to give it an AMI ID. Now I will frequently use a NetBSD AMI, and I don't want to have to remember whatever that identifier is, so I have another alias called "start-netbsd" that calls this function with the right AMI. As we show these aliases and functions, I hope you notice that there's a fair bit of reusing certain building blocks, a pattern we will revisit later this semester when we talk about automation and programming within the System Administration context. But ok, so let's launch one of these instances. By running the 'start-netbsd' alias, we will pass this AMI here into the 'startInstance' function and get back the instance ID. But we need to know the hostname to be able to log in, so let's run 'aws ec2 describe-instances'... ...there it is. But so that's not very convenient. So I have another function that extracts just the hostname for me from an instance ID, called 'iname'. There, that looks better. So let's try to log in... Hmm, this is taking a while. I'm sure you've noticed that when you spin up an instance, it'll take a while for the system to come up. So let's interrupt this here and see if we can't write a little something that lets us know when the system is ready. So here I have a function that uses the 'aws ec2 wait' command for the instance to enter the "running" state. But unfortunately an instance being marked as "running" in AWS does not guarantee that it's fully booted and SSH is running, so we add a little bit of a delay here. This is a bit of suboptimal, but it beats trying over and over again. Although, perhaps you can find a better way? Let's give this a try with a different image. We also often will use the OmniOS operating system, so here we have an alias for that. So we can run the "ec2wait" function like this. Now this will take a little bit of time, but eventually... ...we are notified that the instance should be ready now. And now we can ssh to the instance - yay! What about the other instance? We can use the 'iname' function again: There we go. Alright, so now we have multiple instances running, and I often want to check which ones we have, so for that I have another alias, called "instances". This gives me the instance-IDs, but of course I also often want to see the hostnames, so here we go with the "inames" alias. What if you want both? No problem, we have an alias for that, too. See, I told you that 'jq' is great, didn't I? Alright, time to shut down these instances... ugh, that's so much typing again! There, "term-instance" is much easier. And what if I want to just kill all instance I may have running? There. But be careful with this one! Ok, now both of the instances I just started are shutting down. But note that even when they're shutting down, they still show up in the 'instances' alias. But if I want to know which instances are currently in 'running' state... ...then I find that right now there are none, since I just shut them both down. Alright, so those are just some of the aliases and functions I use on a regular basis. I've put most of those into a file that you can download from the course website if you want to use them as well For that, you can curl it like this. ...and here they are... ...including the various instance types we'll be using... So you can then place that file somewhere convenient... ...and then source it from your shell's startup file. The next time you start a new shell, you'll have all these handy aliases and functions ready for you. Alright, I hope you could play along with this video and see the benefit of customizing your shell environment so that you can save yourself some typing when running the same or close to the same commands. The links here will hopefully also be useful for you. In our next video, we'll go over another warmup exercise for our week 2 topic of storage models and disks. Until then - thanks for watching! Cheers!