AWS – PowerShell – Setting up AWS Tools

AWS Tools for PowerShell are very useful to manage the AWS resources through PowerShell scripts. In order to use AWS Tools, from 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 setting 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 Winodws 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 of 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 below command at the AWS PowerShell prompt.
PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Import-Module .\AWSPowerShell.psd1
Import-Module is the PowerShell’s command, to load the module into the memory. Above command loads the AWSPowerShell module into memory; enabling us to start using AWS PowerShell cmdlets (Commands). Step 5. To verify, whether AWS Tools are working, type below command to list the AWS EC2 Instance details:
PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Get-Ec2Instance
You may see 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 start using it. Step 6. As I mentioned above in Step 4; Windows PowerShell for AWS, tries to call “Initialize-AWSDefaultConfiguration” cmdlet, to setup the AWS configuration; whenever you open the PowerShell for AWS. In Step 4, it was failed to recognize the command; due to AWSPowerShell module was not loaded. Now the module was loaded, using Import-Module cmdlet. And we will setup the AWS configuration using 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 is already exists. I have done the AWS configuration, in below mentioned Article.
The Key details, you will get when you create a User. I have explained, how to add 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 Insatnce details by using “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; Get-EC2Instance command displays all the EC2 Instances in the current region, grouped by Reservation ID. AWS Tools for PowerShell is now Successfully setup to access AWS resources from PowerShell command prompt or through PowerShell scripts. We will discuss more about AWS Tools for PowerShell, through coming Articles. [..] David

Add a Comment

Your email address will not be published.