Created
December 11, 2017 10:43
-
-
Save ilkka/a8356832849b3c1bf5d8b687a9e2092e to your computer and use it in GitHub Desktop.
PowerShell cmdlet for writing an awscli/boto credentials file when you used AWS PowerShell tools to store your creds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Drop this in your profile file and you're good to go. | |
# Creating ~\.aws\credentials file from creds stored in the aws powershell tools | |
function Set-BotoCredentials { | |
[CmdletBinding()] | |
param ( | |
[parameter()] | |
[string] | |
$ProfileName = 'default' | |
) | |
$Credentials = (Get-AWSCredential -ProfileName $ProfileName).GetCredentials() | |
New-Item -Path ${HOME}\.aws -ItemType Directory -ErrorAction Ignore | Out-Null | |
# "false" there means no BOM | |
$Encoding = New-Object System.Text.UTF8Encoding $False | |
$Content = @" | |
[default] | |
aws_access_key_id = $($Credentials.AccessKey) | |
aws_secret_access_key = $($Credentials.SecretKey) | |
"@ | |
[System.IO.File]::WriteAllLines("${HOME}\.aws\credentials", $Content, $Encoding) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment