From the course: Running Microsoft Workloads on AWS
Accessing AWS through PowerShell
From the course: Running Microsoft Workloads on AWS
Accessing AWS through PowerShell
- [Instructor] In the previous video, I showed you how to set up the Windows command prompt environment to access the Amazon Cloud. Now I want to show you how to enable Amazon Cloud access through PowerShell. To do this, we're going to install something called the AWS Tools for PowerShell. So to get started, you can see that I'm in PowerShell and I'm running an elevated PowerShell session. You'll notice the word Administrator in the tab within Windows Terminal indicating that I am indeed in an elevated PowerShell session. So the first thing that we have to do is install a module called aws.tools.installer. So I'll go ahead and install that module, and this is basically a base module. It contains a lot of the dependencies that are going to be used by more service-specific modules. I'll show you how that works a little bit later on. For right now, I'm going to type install-module space -name and then aws.tools.installer. I'll press Enter. And when I do, I get a message saying that the NuGet provider is required. If you don't already have the NuGet provider installed on your machine, you'll get this message. If you do, then PowerShell will simply use the existing provider. In this case, this is a brand new virtual machine that I've set up specifically for this course, so I don't have the NuGet provider installed, so I'm just going to press Y and PowerShell will install the provider. Now I'm asked if I want to install the aws.tools.installer module and it's listed as untrusted. I'm just going to go ahead and press Y to install the module and press Enter and the module is installed. So the next thing that I have to do is to check the execution policy on this machine to make sure that I'm able to run scripts. So I'm going to type Get-ExecutionPolicy and I'll press Enter and you can see that this machine is restricted, so we need to remove that restriction. Now I recommend choosing an execution policy that works well for your organization's security needs. A lot of organizations will go with a remote signed execution policy. I'm just going to set the execution policy on this machine to unrestricted, So I'll type Set-ExecutionPolicy unrestricted, and I'll press Enter and then I'll repeat the Get-ExecutionPolicy command. And now we can see that the execution policy is set to unrestricted. So now we can move forward with the provisioning process. So what we need to do now is to import the module that we've just installed. I'm going to type import-module space and then aws.tools.installer and I'll press Enter and so the module has been imported. The next thing that we would typically do at this point is to install some modules that are specific to the various AWS services. Because the Amazon Cloud makes use of different services, you've already seen some examples of that. For example, in one of the earlier videos, I opened up the IAM service, but there are others. Now these services, when you reference them from PowerShell, they typically follow a specific naming convention. The way that you would reference those services is by typing aws.tools. and then whatever the service name is. So for example, if you wanted to install the module that's specific to the S3 service, then what you would do is you would type Install-AWSToolsModule space and then the name of the module, which in this case is going to be AWS.Tools.S3. And in case you're not familiar with S3, S3 is a storage service in the Amazon Cloud. And then I like to append the cleanup switch, so I'll type -cleanup, and I'll press Enter, and then I'm prompted as to whether or not I want to install the module, I'll press Y and the module is installed. Let's do one more. I'll repeat the command, but this time, I'm going to change S3 to EC2. And once again, EC2 is the service that's used to create virtual machines within the Amazon Cloud. So I'll press Enter. Again, I receive an are you sure prompt. I'll press Y and press Enter and the module is installed. Now as I mentioned, the names of these modules adhere to a strict naming convention, so it's usually pretty easy to guess what the name of a module will be, but Amazon doesn't force you to guess. There is a website that lists all of the different modules and their names. And let me go ahead and show you what that looks like. So here's the page. It's www.powershellgallery.com/packages?q=aws. And you'll notice that we have various package types, including modules and scripts. And if you scroll through here, you can see AWS.Tools.CloudWatch, AWS.Tools.S3, and then AWS.Tools.EC2, and the list goes on. So this is where you would go to confirm a module name if you have trouble guessing what the module name is when you're working within PowerShell. But with that said, let me go ahead and switch back to PowerShell. So the next thing that we have to do is to configure PowerShell to use the credentials that we created in one of the earlier videos. As you'll recall, this consists of an access key and a secret key. And the way that we do this is by using the Set-AWSCredential commandlet. So I'll type Set-AWSCredential space and then -StoreAs and then we have to give this a profile name. Now, if you're going to be using general purpose credentials as I am, then you really want to use the word default as the profile name because then PowerShell will know to use this automatically and it'll just make your life a little bit easier. So I'm going to type default and then space -AccessKey space and then I need to copy the access key from Notepad, so I'm going to click on Notepad, I'll select my access key, right-click on it and choose Copy. I'll go back to PowerShell and press Control + V, and then I'll type space and then -Secretkey space and then I need to switch back over to Notepad. I'll select my secret key, I'll press Control + C, and then I'll switch back over to PowerShell and press Control + V and then paste my secret key and I'll press Enter and so now my credentials have been linked to PowerShell. So how do we test this? How do we know if that worked? Well, what I want to do now is I want to run an EC2-specific commandlet. As you'll recall, EC2 is the platform that you use to create virtual machine instances. And let me do two things. The first thing that I want to do is just clear the screen, I'll type cls and press Enter. The other thing that I want to do is switch back over to the console for a second. So here we are inside of AWS, and I'm looking at the EC2 console. And you'll notice that I have what's known as an EC2 instance. An EC2 instance is essentially a virtual machine that's running in the Amazon Cloud. And this virtual machine instance is called Demo and you can see the instance ID right here and this instance is currently running. Now you don't have to create an instance, I just did this for demonstration purposes because what I want to do is run an EC2-specific command within PowerShell that will display any virtual machines that may exist. So let me go ahead and minimize this. And the commandlet that I'm going to use is Get-EC2Instance. And then the only parameter that I'm going to use with this commandlet is the region, so I'll type space -region, and then I'll type us-east-1 and I'll press Enter and you can see my virtual machine instance. So you'll notice that when I entered the Get-EC2Instance commandlet, I didn't have to supply any credentials. And the reason for that was that I've already linked those credentials to PowerShell. I was able to just go on about my business and run an AWS-related commandlet without having to worry about authenticating into the Amazon Cloud. So that's how you prepare PowerShell for use with AWS. Now, as I mentioned, I'm not going to be doing much from the command line within this course, but I wanted you to at least know how to prepare the command line environments so that you can access AWS from the command prompt as needed.