AWS PowerShell and PowerShell Profile


In my last post Login to Azure PowerShell Options talked about Azure. In this one I will share about AWS.

Before we begin it would be good to get familiar with basic AWS PowerShell and connectivity using PowerShell. Following resources are helpful.

Goal

I want to start using AWS Cmdlets as soon as I have PowerShell launched.

Solution I am using,

Few checks before updating Default Windows PowerShell Profile for Current User.

06012017-11

To find cmdlets which work with the AWS credentials

PS C:\> Get-Command *aws*cred*

06012017-02

To find cmdlets which work with the AWS defaults

PS C:\> Get-Command *aws*defa*

06012017-03

Just to ensure there are not configurations loaded by PowerShell Current User Profile

PS C:\> Get-Variable *aws*

06012017-01

I am expecting “StoredAWSCredentials” and “StoredAWSRegion” to be loaded and available and there is no file available at C:\Users\{UserName}\AppData\Local\AWSToolkit

06012017-04

To set credentials I have added following 5 lines into my PowerShell profile.

06012017-05

$awRegion = 'ap-south-1'
$awAdmin = Import-Csv -Path "C:\Users\{username}\OneDrive\Documents\Cloud\MyAWS\credentials.csv"
Set-DefaultAWSRegion $awRegion
Set-AWSCredentials -AccessKey $awAdmin.'Access Key Id' -SecretKey $awAdmin.'Secret Access Key' -StoreAs "MSAWPS"
Initialize-AWSDefaults -ProfileName "MSAWPS"

I have a credentials csv file in which access key and secret key for my admin account is stored. I am importing that from my onedrive path and using it in Set-AWSCredentials command.

Now launch PowerShell as Administrator and notice few changes. First there a file called RegisteredAccounts.json created at

C:\Users\{UserName}\AppData\Local\AWSToolkit

06012017-06

Open it in notepad or your favorite tool. I am using Visual Studio Code. The file looks like below,

06012017-07

This time some AWS configurations are loaded by PowerShell Current User Profile

PS C:\> Get-Variable *aws*

06012017-08

You can verify that credentials are loaded and available for use.

PS C:\> Get-AWSCredentials -ListProfiles

06012017-09

You can directly start using AWS cmdlets. Notice I don’t have to supply the credentials or profile as it’s already set and initialized as default.

PS C:\> Get-IAMUser
PS C:\> Get-IAMUsers

06012017-10

That’s it for now.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s