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.
- Setting up the AWS Tools for Windows PowerShell
- Using AWS Credentials
- Handling Credentials with AWS Tools for Windows PowerShell
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.
To find cmdlets which work with the AWS credentials
PS C:\> Get-Command *aws*cred*
To find cmdlets which work with the AWS defaults
PS C:\> Get-Command *aws*defa*
Just to ensure there are not configurations loaded by PowerShell Current User Profile
PS C:\> Get-Variable *aws*
I am expecting “StoredAWSCredentials” and “StoredAWSRegion” to be loaded and available and there is no file available at C:\Users\{UserName}\AppData\Local\AWSToolkit
To set credentials I have added following 5 lines into my PowerShell profile.
$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
Open it in notepad or your favorite tool. I am using Visual Studio Code. The file looks like below,
This time some AWS configurations are loaded by PowerShell Current User Profile
PS C:\> Get-Variable *aws*
You can verify that credentials are loaded and available for use.
PS C:\> Get-AWSCredentials -ListProfiles
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
That’s it for now.
You must be logged in to post a comment.