aws-shell, released by AWS labs, is a rich command-line shell with built-in autocompletion and help documentation. It’s very similar to the previous interactive commands we learned about for Microsoft Azure and Google Cloud. It also offers robust auto-completion, including the ability to autocomplete resources such as EC2 instance names.
For most commands, we simply prefix the command with an exclamation point; for example, !ls will run the ls shell command. To change the current working directory of aws-shell, we can use the .cd command (it’s prefixed with a period). Finally, we can pipe the JSON output of any command to a shell command—anything after the pipe character (|) is assumed to be a shell command. For example, ec2 describe-instances | grep production would search the JSON output for the word production.
The final convenience of aws-shell is its autocompletion capabilities. For certain commands that take IDs of AWS resources, we can use tab completion to complete these IDs. For example, if we wanted to start an EC2 instance with the i-a5e9a33f0 instance ID, aws-shell can tab-complete this instance ID as part of the ec2 start-instances command.
If you encounter the below error while running the aws-shell command:
aws-shell: command not found
you may try installing the below package as per your choice of distribution.
|OS X||brew install aws-shell|
|Debian||apt-get install aws-shell|
|Ubuntu||apt-get install aws-shell|
|Kali Linux||apt-get install aws-shell|
|Fedora||dnf install aws-shell|
|Raspbian||apt-get install aws-shell|
The aws-shell utility works with the aws utility to provide an interactive CLI experience. You use it to make working with aws easier. The following sections discuss how you can use aws-shell to make your script and batch-process experience better.
Auto-completion: As you type commands, you see a list of available options to complete the next step. For example, after you type aws, you see a list of services that you can add as the next step in the command process.
Auto-suggestion: If the shell recognizes a pattern to the values you type, it gives you a completed command. Pressing Tab automatically enters the remaining text.
Command history: Even though most command-prompt and terminal-window implementations retain a command history, the information is available for only the current session. The aws-shell utility stores this information in a file for later use.
Dot (.) commands: The aws-shell gives you access to additional aws-shell–specific commands through the dot (.) prompt. Here are a few examples:
- .edit: Provides the means for saving the commands you type as part of a shell script.
- .profile: Modifies the profile used to execute commands so that you don’t have to include the –profile argument every time you type a command.
- .cd: Changes the directory to the specified location on disk.
Fuzzy searches: You may not remember an argument or other command component precisely. Typing a value that appears as part of the actual argument displays a list of suggestions that you can use in place of that part you remember.
Inline documentation: Help is always available as part of the shell. As you type values, the shell automatically displays help for that value so that you can be sure you’re typing the right information.
Server-side auto-complete: Typing a command component that requires a server-side value, such as an ARN, usually requires a lookup on your part. When using aws-shell, the shell performs the lookup for you and displays a list of acceptable values.
Shell command access: If you need to access the underlying operating system commands, type an exclamation mark (!) before the command. For example, type ! dir and press Enter to obtain a directory listing on a Windows system.
Shorthand auto-complete: You can use shorthand notation to define a specific longer sequence of commonly used commands. Typing the shorthand form is the same as typing the full sequence.
Toolbar options: The status bar shows a list of function keys that you can press to obtain specific functionality from aws-shell. For example, you can turn fuzzy searches on or off as needed.