When getting started with new platform, I like to learn the command-line first before any of the UI tools, i.e., git over Git Tower.

The AWS CLI is extremely powerful however trying to remember the breadth of commands available is a challenge, so I set out to get autocomplete working.

However

Unfortunately, Amazon has only provided documentation for autocompletion on Unix-like systems and that is not configured out-of-the-box.

Reading the above AWS documentation and enabling similar features for dotnet using Powershell, I was come up with the following.

Open the PowerShell profile using Code or your favourite editor.

code $PROFILE

And at the end add the following snippet.

# AWS CLI
# PowerShell parameter completion shim for the aws CLI
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
    $completer = "C:\Python\lib\site-packages\awscli\completer.pyc"
    python.exe $completer "$wordToComplete" $cursorPosition | ForEach-Object {
        [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
    }
}

Breaking down the above.

  • Register-ArgumentCompleter is a relatively unknown feature that enables unix-similar shell completion (docs).
  • The script block will execute when aws tab is pressed.
  • Using the completer provided by AWS CLI (N.B this may be in a different location on your machine) we hook in the partial $wordToComplete and the $cursorPosition.
  • Done :lightning: