AWS – PowerShell – Setting up AWS Tools

AWS Tools for PowerShell is very useful to manage the AWS resources through PowerShell scripts. In order to use AWS Tools, from the PowerShell command prompt or through PowerShell scripts, you must install the AWS Tools for PowerShell.

In this article, I am going to explain, how to set up the AWS Tools for PowerShell environment.

Step 1. Download the AWS Tools for PowerShell.

I have downloaded AWS Tools for Windows Installer, “AWSToolsAndSDKForNet_sdk-3.3.342.0_ps-3.3.335.0_tk-1.14.4.1.msi“; to install it on Windows 7 64-bit Operating System.

Step 2. Install AWS Tools for PowerShell, by double-clicking on the downloaded .msi file.

Windows Installer will take you through the wizard, to install the AWS Tools.

Step 3. Once the installation is done, you will find the shortcut to Open “Windows PowerShell for AWS” in StartMenu.

Click on Windows StartMenu > Select All Programs > Select Amazon Web Services > and then Select “Windows PowerShell for AWS” shortcut. It will open PowerShell command prompt.

Step 4. You may see the below Error message, after the Windows PowerShell for AWS is open: If you do not see this Error message; you can directly go to Step 6.

The term 'Initialize-AWSDefaultConfiguration' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.At line:1 char:3
+& Initialize-AWSDefaultConfiguration
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 	+ CategoryInfo          : ObjectNotFound: (Initialize-AWSDefaultConfiguration:String) [], CommandNotFoundException
 	+ FullyQualifiedErrorId : CommandNotFoundException

When you click on the “Windows PowerShell for AWS” shortcut, it automatically runs the “Initialize-AWSDefaultConfigurationcmdlet, to initiate AWS default configuration to allow to access the AWS resources. The above Error is mainly because the module “AWSPowerShell.dll” was not loaded into the memory. To resolve, this issue; either you need to Restart your computer after the installation; Or, type the below command at the AWS PowerShell prompt.

PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Import-Module .\AWSPowerShell.psd1

Import-Module is PowerShell’s command, to load the module into the memory. The above command loads the AWS PowerShell module into memory; enabling us to start using AWS PowerShell cmdlets (Commands).

Step 5. To verify, whether AWS Tools are working, type the below command to list the AWS EC2 Instance details:

PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Get-Ec2Instance

You may see the below message, instead of displaying EC2 Instance details:

PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Get-Ec2Instance
Get-EC2Instance : No credentials specified or obtained from persisted/shell defaults.At line:1 char:1
+ Get-Ec2Instance
+ ~~~~~~~~~~~~~~~
   + CategoryInfo : InvalidOperation: (Amazon.PowerShe…2InstanceCmdlet:GetEC2InstanceCmdlet) [Get-EC2Insta
nce], InvalidOperationException
   + FullyQualifiedErrorId : InvalidOperationException,Amazon.PowerShell.Cmdlets.EC2.GetEC2InstanceCmdlet

Look at the message, “No credentials specified“; this is because, AWS has to be configured, before starting using it.

Set up the AWS configuration

Step 6. As I mentioned above in Step 4; Windows PowerShell for AWS tries to call the “Initialize-AWSDefaultConfiguration” cmdlet, to set up the AWS configuration; whenever you open the PowerShell for AWS. In Step 4, it was failed to recognize the command; due to the AWS PowerShell module was not loaded. Now the module was loaded, using the Import-Module cmdlet. And we will set up the AWS configuration using the Initialize-AWSDefaultConfiguration command.

Step 7. Type below command at PowerShell for AWS prompt:

PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Initialize-AWSDefaultConfiguration

Saved credentials found
Please choose one of the following stored credentials to use
[] <Create new credentials set>  [] default  [?] Help (default is "<Create new credentials set>"): default

Credentials
Please enter your AWS Access and Secret Keys
AWS Access Key: xxxxxxxxxxxxxxx
AWS Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The command prompts to enter; AWS Access Key & AWS Secret Key details. Enter the Key details and Press Enter key. This sets the AWS configuration. Have you noticed the message “Saved credentials found“.? This is because the configuration already exists. I have done the AWS configuration, in the below-mentioned article.


The Key details, you will get when you create a User. I have explained, how to add a User in my previous Article “AWS : Identity and Access Management (IAM) – Add User “. Also read, “AWS CLI : AWS Configuration and Connect to EC2 Instance” for setting up the AWS configuration.


Step 8. Now again, we try to access the EC2 Instance details by using the Get-EC2Instance command. Type below command at PowerShell for AWS prompt:

PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Get-EC2Instance

GroupNames    : {}
Groups        : {}
Instances     : {MyKeyPair}
OwnerId       : ##############
RequesterId   :
ReservationId : r-xxxxxxxxxxxxxxxx

Observe the result; the Get-EC2Instance command displays all the EC2 Instances in the current region, grouped by Reservation ID. AWS Tools for PowerShell is now Successfully set up to access AWS resources from the PowerShell command prompt or through PowerShell scripts. We will discuss more AWS Tools for PowerShell, through coming Articles.

 

[..] David

AWS – PowerShell – Setting up AWS Tools

Leave a Reply

Your email address will not be published.

Scroll to top
Exit mobile version