Configuring command completion in the AWS CLI (original) (raw)
The AWS Command Line Interface (AWS CLI) includes a bash-compatible command-completion feature that enables you to use the Tab key to complete a partially entered command. On most systems you need to configure this manually.
For information on the AWS CLI version 2 auto-prompt feature instead, see Enabling and using command prompts in the AWS CLI.
Topics
- How it works
- Configuring command completion on Linux or macOS
- Configuring command completion on Windows
How it works
When you partially enter a command, parameter, or option, the command-completion feature either automatically completes your command or displays a suggested list of commands. To prompt command completion, you partially enter in a command and press the completion key, which is typically Tab
in most shells.
The following examples show different ways that you can use command completion:
- Partially enter a command and press
Tab
to display a suggested list of commands.
$ aws dynamodb dTAB
delete-backup describe-global-table
delete-item describe-global-table-settings
delete-table describe-limits
describe-backup describe-table
describe-continuous-backups describe-table-replica-auto-scaling
describe-contributor-insights describe-time-to-live
describe-endpoints
- Partially enter a parameter and press
Tab
to display a suggested list of parameters.
$ aws dynamodb delete-table --TAB
--ca-bundle --endpoint-url --profile
--cli-connect-timeout --generate-cli-skeleton --query
--cli-input-json --no-paginate --region
--cli-read-timeout --no-sign-request --table-name
--color --no-verify-ssl --version
--debug --output
- Enter a parameter and press
Tab
to display a suggested list of resource values. This feature is available only in the AWS CLI version 2.
$ aws dynamodb delete-table --table-name TAB
Table 1 Table 2 Table 3
Configuring command completion on Linux or macOS
To configure command completion on Linux or macOS, you must know the name of the shell you're using and the location of the aws_completer
script.
Note
Command completion is automatically configured and enabled by default on Amazon EC2 instances that run Amazon Linux.
Topics
Confirm the completer's folder is in your path
For the AWS completer to work successfully, the aws_completer
needs to be in your shell's path. The which
command can check if the completer is in your path.
$ which aws_completer
/usr/local/bin/aws_completer
If the which command can't find the completer, then use the following steps to add the completer's folder to your path.
Step 1: Locate the AWS completer
The location of the AWS completer can vary depending on the installation method used.
- Package Manager - Programs such as
pip
,yum
,brew
, andapt-get
typically install the AWS completer (or a symlink to it) to a standard path location.- If you used
pip
without the--user
parameter, the default path is/usr/local/bin/aws_completer
. - If you used
pip
with the--user
parameter the default path is/home/`username`/.local/bin/aws_completer
.
- If you used
- Bundled Installer - If you used the bundled installer, the default path is
/usr/local/bin/aws_completer
.
If all else fails, you can use the find
command to search your file system for the AWS completer.
$ find / -name aws_completer
/usr/local/bin/aws_completer
Step 2: Identify your shell
To identify which shell you're using, you can use one of the following commands.
- echo $SHELL – Displays the shell's program file name. This usually matches the name of the in-use shell, unless you launched a different shell after logging in.
$ echo $SHELL
/bin/bash
- ps – Displays the processes running for the current user. One of them is the shell.
$ ps
PID TTY TIME CMD
2148 pts/1 00:00:00 bash
8756 pts/1 00:00:00 ps
Step 3: Add the completer to your path
- Find your shell's profile script in your user folder.
$ ls -a ~/
. .. .bash_logout .bash_profile .bashrc Desktop Documents Downloads
- Bash–
.bash_profile
,.profile
, or.bash_login
- Zsh–
.zshrc
- Tcsh–
.tcshrc
,.cshrc
, or.login
- Add an export command at the end of your profile script that's similar to the following example. Replace
`/usr/local/bin/`
with the folder that you discovered in the previous section.
export PATH=/usr/local/bin/:$PATH
- Reload the profile into the current session to put those changes into effect. Replace
`.bash_profile`
with the name of the shell script you discovered in the first section.
$ source ~/.bash_profile
Enable command completion
After confirming the completer is in your path, enable command completion by running the appropriate command for the shell that you're using. You can add the command to your shell's profile to run it each time you open a new shell. In each command, replace the/usr/local/bin/
path with the one found on your system in Confirm the completer's folder is in your path.
bash
– Use the built-in commandcomplete
.
$ complete -C '/usr/local/bin/aws_completer' aws
Add the previous command to ~/.bashrc
to run it each time you open a new shell. Your ~/.bash_profile
should source~/.bashrc
to ensure that the command is also run in login shells.
zsh
– To run command completion, you need to runbashcompinit
by adding the following autoload line at the end of your~/.zshrc
profile script.
$ autoload bashcompinit && bashcompinit
$ autoload -Uz compinit && compinit
To enable command completion, use the built-in command complete
.
$ complete -C '/usr/local/bin/aws_completer' aws
Add the previous commands to ~/.zshrc
to run it each time you open a new shell.
tcsh
– Complete fortcsh
takes a word type and pattern to define the completion behavior.
> complete aws 'p/*/`aws_completer`/'
Add the previous command to ~/.tschrc
to run it each time you open a new shell.
After you've enabled command completion, Verify command completion is working.
Verify command completion
After enabling command completion, reload your shell, enter a partial command, and pressTab to see the available commands.
$ aws sTAB
s3 ses sqs sts swf
s3api sns storagegateway support
Configuring command completion on Windows
Note
For information on how PowerShell handles their completion, including their various completion keys, see about_Tab_Expansion in the Microsoft PowerShell Docs.
To enable command completion for PowerShell on Windows, complete the following steps in PowerShell.
- Open your
$PROFILE
with the following command.
PS C:\> Notepad $PROFILE
If you do not have a $PROFILE
, create a user profile using the following command.
PS C:\> if (!(Test-Path -Path $PROFILE ))
{ New-Item -Type File -Path $PROFILE -Force }
For more information on PowerShell profiles, see How to Use Profiles in Windows PowerShell ISE on the Microsoft Docs website. 2. To enable command completion, add the following code block to your profile, save, and then close the file.
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
param($commandName, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>w</mi><mi>o</mi><mi>r</mi><mi>d</mi><mi>T</mi><mi>o</mi><mi>C</mi><mi>o</mi><mi>m</mi><mi>p</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>e</mi><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">wordToComplete, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal" style="margin-right:0.02778em;">or</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal">m</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mpunct">,</span></span></span></span>cursorPosition)
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>n</mi><mi>v</mi><mo>:</mo><mi>C</mi><mi>O</mi><mi>M</mi><msub><mi>P</mi><mi>L</mi></msub><mi>I</mi><mi>N</mi><mi>E</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">env:COMP_LINE=</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">COM</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">L</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal" style="margin-right:0.05764em;">NE</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>wordToComplete
if ($env:COMP_LINE.Length -lt $cursorPosition){
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>n</mi><mi>v</mi><mo>:</mo><mi>C</mi><mi>O</mi><mi>M</mi><msub><mi>P</mi><mi>L</mi></msub><mi>I</mi><mi>N</mi><mi>E</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">env:COMP_LINE=</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">COM</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">L</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal" style="margin-right:0.05764em;">NE</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>env:COMP_LINE + " "
}
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>e</mi><mi>n</mi><mi>v</mi><mo>:</mo><mi>C</mi><mi>O</mi><mi>M</mi><msub><mi>P</mi><mi>P</mi></msub><mi>O</mi><mi>I</mi><mi>N</mi><mi>T</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">env:COMP_POINT=</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">COM</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.1389em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.13889em;">P</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.02778em;">O</span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal" style="margin-right:0.13889em;">NT</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>cursorPosition
aws_completer.exe | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mrow></mrow><mo separator="true">,</mo><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msubsup><mi>P</mi><mi>a</mi><mi>r</mi><mi>a</mi><mi>m</mi><mi>e</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>V</mi><mi>a</mi><mi>l</mi><mi>u</mi><msup><mi>e</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">_, 'ParameterValue', </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.135em;vertical-align:-0.3831em;"></span><span class="mord"><span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-2.453em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mpunct mtight">,</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.3831em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">am</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">er</span><span class="mord mathnormal">Va</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">u</span><span class="mord"><span class="mord mathnormal">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mpunct">,</span></span></span></span>_)
}
Remove-Item Env:\COMP_LINE
Remove-Item Env:\COMP_POINT
}
- After enabling command completion, reload your shell, enter a partial command, and press Tab to cycle through the available commands.
$ aws sTab
$ aws s3
To see all available commands available to your completion, enter a partial command and press Ctrl + Space.
$ aws sCtrl + Space
s3 ses sqs sts swf
s3api sns storagegateway support