Just a quick guide to get the Amazon Web Services (AWS) command line tools installed and configured on an Apple Mac running Mountain Lion.
duck Cyberduck for the command line interface (CLI). The universal file transfer tool duck which runs in your shell on Linux and OS X or your Windows command line prompt. Edit files on remote servers, download, upload and copy between servers with FTP, SFTP or WebDAV plus support for cloud storage Amazon S3 & OpenStack Swift deployments. On Linux or macOS, you can use the bundled installer to install version 1 of the AWS Command Line Interface (AWS CLI). The bundled installer includes all dependencies and can be used offline. The bundled installer doesn't support installing to paths that contain spaces.
The first task was to get PIP installed:
Then it's a simple case of using PIP to to install the AWS CLI:
After a few minutes you should have the CLI tools installed. The final task is to set up your credentials. Create the file $HOME/.aws/config
, it should contain something like the following:
You should replace these values with your own access keys and preferred region. For extra credit, if you're a Bash shell user, you can enable command completion:
There's much more information on the AWS CLI available from Amazon.
5 Tips for Getting More Out of the AWS CLI
AWS command line interface (CLI) enables you to control your AWS environment from your local client terminal. You can use CLI to configure, monitor, and automate resource management. This article provides a walkthrough that explains how to use AWS CLI. You will also learn five very useful AWS CLI commands.
How to Use the AWS CLI
The AWS command line interface (CLI) is a tool provided by Amazon to help you manage your resources and services. It enables you to control your environment from the terminal of your local client. You can use it to change configurations, monitor assets, and automate the management of resources through scripting.
How to download and install the AWS CLI on Windows
- Download the 64-bit installer or 32-bit installer and run it.
- Confirm the installation by running aws -version in the cmd command prompt.
- Run aws configure to provide your access AWS Access Key ID, AWS Secret Access Key, and Amazon region.
How to download and install the AWS CLI on Mac or Linux
- Ensure you have Python 2.6.3 or later installed. Check by running $ python –version
- Run the following commands:
- Edit the ~/.aws/config file and add your Access Key ID, Secret Access Key, and region.
- Protect the config file by running chmod 600 ~/.aws/config
Basic command structure
Most AWS commands have the following structure:
You can see the full documentation for details of all commands.
AWS Command Line Interface Tricks and Shortcuts
When getting started with the AWS CLI, there are a variety of tricks and shortcuts you can use to increase your productivity. Below are a few that are particularly useful.
Drilling down for help
Your cloud environment is made of a collection of services. Each service has a different set of options and commands that can be difficult to remember. Rather than having to search through the documentation to find these options and commands, you can use the help command built into the AWS CLI.
To access this command, you need to type aws help. This pulls up a list of globally available commands. You can refine this command by inserting the service name for more specific options. For example, if you're trying to manage your EBS volumes but have forgotten which commands you need, you can aws ebs help –.
Once you find the command you need, you can even drill down further by inserting the command name after the service name. For example, aws ebs describe-service help. This enables you to quickly access only the information you need. Alternatively, you can use aws help topics to view a full list of your available options.
Setting up auto-complete for commandsBuilt-in to the AWS CLI is an auto-complete feature for commands. This feature helps speed your CLI use by predicting which commands you are typing and enabling you to quickly insert text with the Tab key.
This feature is preconfigured for Amazon Linux but may require some configuration if you are using another OS. For example, on non-Linux platforms, developers must define the location of the AWS_Completer script and the name of the shell in use.
To accomplish this, you can use the echo $SHELL command. This will tell you which shell you're using if you aren't sure. Then, you can use the Which AWS_Completer command to find the location of your script.
Create command templates with skeletonsOne practice when working with collections of complex commands is to create text files containing those commands. These can be shared amongst teams and referenced as needed. However, these files can be a pain to modify or update.
As an alternative, the AWS CLI includes utilities that you can use to generate a skeleton. Skeletons enable you to modify input parameters for complex commands using JSON files as opposed to scripts. To create a skeleton, you can use the command –generate-cli-skeleton.
Another option is to implement chains of commands from the CLI. This tool enables you to combine commands to be run sequentially or to drive future commands with the output of the current one.
5 Super Useful AWS CLI Commands
Tablet for mac drawing. Now that you understand a few of the tricks and shortcuts available to you, it may be helpful to see some commands in action. Below are some of the most commonly used commands and ones you may want to remember.
Delete an S3 bucket and all its contents
S3 buckets can grow to massive sizes, with thousands of files contained within. While you can individually delete files, this is time-consuming and unnecessary if you know the bucket is unneeded.
Rather than going through one by one, you can duplicate any files you may need and then delete the bucket as a whole. The command to accomplish this is:
Display subsets of all available ec2 images
Aws Cli For Mac
When managing EC2 instances, you may be unsure which images you are using. Rather than individually checking, you can call up a description of all available images. You can use this command on its own, or you can filter the images by type. For example, the following command defines available images built on Ubuntu as called from a Mac or Linux machine:
List users in a different format
When viewing lists of users, especially long lists, the format can make interpretation and use a challenge. When displaying these lists, the format depends on the default you have set.However, you may need that format for other processes while manual list calls are infrequent.
Rather than manually reformatting lists or temporarily modifying defaults, you can output lists in a table format. The following command can help you achieve this:
Move S3 bucket to a different location
Sometimes, rather than deleting buckets what you really need is just to move the files to the appropriate location. You can do this by copying and then deleting the unnecessary duplicate but this is slow and prone to error. A better alternative is to move the bucket with the following command. This example moves a bucket from the US West 1 region to the US West 2 region.
Most AWS commands have the following structure:
You can see the full documentation for details of all commands.
AWS Command Line Interface Tricks and Shortcuts
When getting started with the AWS CLI, there are a variety of tricks and shortcuts you can use to increase your productivity. Below are a few that are particularly useful.
Drilling down for help
Your cloud environment is made of a collection of services. Each service has a different set of options and commands that can be difficult to remember. Rather than having to search through the documentation to find these options and commands, you can use the help command built into the AWS CLI.
To access this command, you need to type aws help. This pulls up a list of globally available commands. You can refine this command by inserting the service name for more specific options. For example, if you're trying to manage your EBS volumes but have forgotten which commands you need, you can aws ebs help –.
Once you find the command you need, you can even drill down further by inserting the command name after the service name. For example, aws ebs describe-service help. This enables you to quickly access only the information you need. Alternatively, you can use aws help topics to view a full list of your available options.
Setting up auto-complete for commandsBuilt-in to the AWS CLI is an auto-complete feature for commands. This feature helps speed your CLI use by predicting which commands you are typing and enabling you to quickly insert text with the Tab key.
This feature is preconfigured for Amazon Linux but may require some configuration if you are using another OS. For example, on non-Linux platforms, developers must define the location of the AWS_Completer script and the name of the shell in use.
To accomplish this, you can use the echo $SHELL command. This will tell you which shell you're using if you aren't sure. Then, you can use the Which AWS_Completer command to find the location of your script.
Create command templates with skeletonsOne practice when working with collections of complex commands is to create text files containing those commands. These can be shared amongst teams and referenced as needed. However, these files can be a pain to modify or update.
As an alternative, the AWS CLI includes utilities that you can use to generate a skeleton. Skeletons enable you to modify input parameters for complex commands using JSON files as opposed to scripts. To create a skeleton, you can use the command –generate-cli-skeleton.
Another option is to implement chains of commands from the CLI. This tool enables you to combine commands to be run sequentially or to drive future commands with the output of the current one.
5 Super Useful AWS CLI Commands
Tablet for mac drawing. Now that you understand a few of the tricks and shortcuts available to you, it may be helpful to see some commands in action. Below are some of the most commonly used commands and ones you may want to remember.
Delete an S3 bucket and all its contents
S3 buckets can grow to massive sizes, with thousands of files contained within. While you can individually delete files, this is time-consuming and unnecessary if you know the bucket is unneeded.
Rather than going through one by one, you can duplicate any files you may need and then delete the bucket as a whole. The command to accomplish this is:
Display subsets of all available ec2 images
Aws Cli For Mac
When managing EC2 instances, you may be unsure which images you are using. Rather than individually checking, you can call up a description of all available images. You can use this command on its own, or you can filter the images by type. For example, the following command defines available images built on Ubuntu as called from a Mac or Linux machine:
List users in a different format
When viewing lists of users, especially long lists, the format can make interpretation and use a challenge. When displaying these lists, the format depends on the default you have set.However, you may need that format for other processes while manual list calls are infrequent.
Rather than manually reformatting lists or temporarily modifying defaults, you can output lists in a table format. The following command can help you achieve this:
Move S3 bucket to a different location
Sometimes, rather than deleting buckets what you really need is just to move the files to the appropriate location. You can do this by copying and then deleting the unnecessary duplicate but this is slow and prone to error. A better alternative is to move the bucket with the following command. This example moves a bucket from the US West 1 region to the US West 2 region.
Aws Cli For Mac Brew
List all of your instances that are currently stopped and the reason for the stop
Downtime in your cloud environment can be a nightmare, ruining productivity and causing revenue loss. When downtime occurs, you need to quickly identify which instances are affected and what caused the outage. You can accomplish this with a command like the following one.
Aws Cli For Mac
Conclusion
Hopefully, this article has helped you better understand how to use AWS CLI. By now, you should be able to download and install AWS CLI on Windows, Mac, or Linux. Remember that whenever you need a reference, you can frill down for help, rather than go look for the documentation. You can also set up auto-complete for commands, and create command templates with skeletons. These three tricks, if implemented continually, can save you a lot of time and effort as you scale up your operations.
See Also
- jq command