Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

AWS Command Line Interface timesaving tricks and shortcuts

While some developers prefer to work with a GUI, the AWS Command Line Interface cuts through the clutter and can save dev teams some much-needed time.

The AWS Command Line Interface makes it easier for developers to tune AWS infrastructures using simple commands....

The CLI streamlines the ability to check on running instances, tune configurations and perform other tasks -- without perusing long menus of options from GUI tools.

The AWS Command Line Interface (CLI) also eases service management and uses scripts to automate processes. Once the scripts are set up, developers can maintain configuration consistency using source code control tools.

AWS CLI is easy to install on Windows, Mac and UNIX clients. Developers can boost its power through the use of shell scripting environments for running complex tasks. They can also set up JSON skeletons as templates for commonly performed tasks.

At the AWS re:Invent 2015 conference, AWS CLI engineer James Saryerwinnie introduced some different approaches for using AWS CLI as a toolkit to create shell scripts. Some patterns to consider are connecting a single output to a single command, mapping list output to multiple CLI calls, storing JSON documents and confirming that resources exist. Code examples for these different techniques are available on GitHub.

Drilling down for help

A cloud infrastructure is built on top of a collection of services, each of which has different commands and options available. In the middle of a project, a developer may want to quickly identify commands, settings and the proper format for a particular service. AWS CLI makes it easy to drill down to these options using a hierarchical help command.

Type aws help to pull up a list of globally available commands; type in the service name followed by help to find high-level commands for a particular service. For example, Elastic Compute Cloud (EC2) would be aws ec2 help --. Developers can pull up the input format and options for a particular command by entering the command name after the service name, such as aws ec2 describe-service help. A list of available help topics is also available by typing aws help topics.

Setting up auto-complete for commands

Manually typing commands each time you need to use them can be tedious and time-consuming. AWS CLI includes a command-completion feature to partially automate this process; developers just need to hit the Tab key while typing a command. This may require some configuration, depending on how the CLI was installed, and it is preconfigured on Amazon Linux. On other platforms, developers need to specify the name of the shell and the location of the AWS_Completer script.

The echo $SHELL command identifies the current shell. The Which AWS_Completer command shows the location of the AWS_Completer script. But note that Bash, tcsh and zsh shells each require different commands to launch.

Override default configuration settings

AWS CLI is easy to install on Windows, Mac and UNIX clients. Developers can boost its power through the use of shell scripting environments for running complex tasks.

Developers may need to bounce between different profiles, regions, output formats or endpoints while working on a project. One good practice is to take advantage of AWS' long Command Line options. Developers implement these by using two hyphens in front of the setting, such as --profile, --region, --output or --endpoint-url. This can make it easier to check resources in different regions or temporarily change the output format to read a particular type of information.

Developers can also run a series of commands using different configuration settings as a probe to see where instances are running.

Create command templates with skeletons

Developers can take several approaches to manage a collection of complex commands within a project. One practice is to store these commands as text files on a local computer or shared directory. A better practice is to manage these commands using a source code repository. This can make it easier to work with modifications and updates to the basic scripts.

AWS CLI also includes a set of tools for generating skeletons that modify input parameters for a complex command. These are available via the --generate-cli-skeleton command with EC2 instances. This makes it easier to modify the parameters using a JSON configuration file, rather than the script.

It's also possible to use the AWS Command Line Interface to implement chains of commands to perform complex tasks. For example, a developer may want to combine commands so they run sequentially. It is also possible to use the output of one command to drive subsequent commands. In other cases, it's best to modify the output of the command to work with different text processing tools, like grep, sed or awk.

AWS-shell tool improves the CLI experience

The AWS Command Line Interface can make it easy to access thousands of commands available across Amazon services. But the interface can be difficult to navigate and read, especially for longer outputs. Developers might want to take a look at the AWS-shell tool to improve the development experience. The tool includes support for fuzzy auto-completion of commands, options and resource identifiers, which make it easier to type in the beginning of a longer command and then scroll down to find the best choice.

The aws-shell also includes support for dynamic in-line documentation of commands and options. With it, developers can see how to format a particular command as it is being typed, rather than performing a separate help query. There are also tools for improving piping from text files and JSON documents. At the end of a session, the aws-shell allows developers to save new commands into a text file for later use.

Next Steps

AWS configuration management tools simplify deployments

Management tools help control your AWS cloud

Top PowerCLI scripts for VSphere admins

This was last published in May 2016

Dig Deeper on AWS architecture and design



Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What is your go-to CLI shortcut?