Skip to content

Instantly share code, notes, and snippets.

@ilkka
Created December 11, 2017 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilkka/a8356832849b3c1bf5d8b687a9e2092e to your computer and use it in GitHub Desktop.
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
# 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