Using the AWS Command Line Interface | Linux

So far, we have learned how to install the AWS line and how to configure it. Now for the fun part- using the AWS command line interface to manage our services!

Interaction

Before we use the CLI to interact with AWS, we need to learn how to structure our commands. This might sound complicated, but AWS commands are pretty easy to get the hang of. Think of it as a sentence in English- different parts of the command do different things. Once you’re comfortable with the structure, you’ll be able to manage your infrastructure like a true professional.

Basic Usage

The AWS CLI commands use a multipart structure. This means each command and subcommand are written in consecutive order. The options or parameters can be provided in any order, but it’s typically a good idea to specify them after the related command.

Here’s an example of the structure:

aws [options] [parameters]

What is a command?

A top-level command, or simply command, corresponds to the Amazon Web Service you want to call an action on. For instance, the command could be ec2 for Amazon EC2, iam for AWS Identity and Access Management, or s3 for Amazon S3.

What is a subcommand?

A subcommand represents an action that you would like to perform using the Amazon Web Service such as, launching an instance using Amazon EC2, creating new IAM users and groups using AWS Identity and Access Management, or managing buckets using Amazon S3.

You can find more information on commands and subcommands for specific services here.

What are options and parameters?

The options and parameters are usually optional, depending on the command or subcommand. They represent any data or flags needed to specify a certain behavior.

NOTE: If you specify an exclusive parameter multiple times, only the last value will be used.

What are the valid parameter types?

The valid parameter types depend on the command or subcommand used. We encourage you to use the help command for more information if you ever get stuck. The common parameter types that you will see are strings, numbers, lists, maps, BLOBs, timestamps, and JSON structures.

  • String – Contains alphanumeric characters, symbols, and whitespace from the ASCII character set. Strings that contain whitespace must be surrounded by quotes. However, use of symbols and whitespace other than the standard space character is not recommended and may cause issues when using the AWS CLI.
  • List – One or more strings separated by spaces.
  • Map – Sequence of key-value pairs specified in JSON or shorthand syntax.
  • BLOB – Binary object. Blob parameters take a path to a local file that contains binary data. The path should not contain any protocol identifier such as http:// or file://.
  • Timestamp – Timestamps are formatted per the ISO 8601 standard. These are sometimes referred to as “DateTime” or “Date” type parameters. Acceptable timestamp formats include:YYYY-MM-DDThh:mm:ss.sssTZD (UTC), e.g., 2014-10-01T20:30:00.000Z YYYY-MM-DDThh:mm:ss.sssTZD (with offset), e.g., 2014-10-01T12:30:00.000-08:00 YYYY-MM-DD, e.g., 2014-10-01 Unix time in seconds, e.g. 1412195400

You can find more information on specifying parameters here.

Help Breakdown

Confused? Need help? Don’t know how to structure a multipart command? No worries. If you’re ever stuck, you can add help to a command to see a list of ways it can be used:

aws help 

aws help 

aws help

After typing help, you may feel a little overwhelmed. It contains a ton of information, but don’t worry! Let’s break down each part:

  • Name – The name of the command or subcommand.
  • Description – A description of the API operation that the command or subcommand invokes.
  • Synopsis – The command and its options. If an option is shown in square brackets, it is either optional, has a default value, or has an alternative option that can be used instead.
  • Options – A description of each of the options shown in the synopsis.
  • Examples – Shows how to use the command and its options. If there isn’t an example available for a command, you can request one using the feedback button on the bottom of the related API documentation page.
  • Output – These are descriptions of each of the fields and data types returned in the response from AWS.

You can find more information in the user guide under the getting help section.

More Information

What services are available through the AWS CLI?

There are a number of services that can be used through the AWS CLI, including:

  • DynamoDB
  • Amazon EC2
  • Amazon Glacier
  • AWS Identity and Access Management
  • Amazon S3
  • Amazon SNS
  • Amazon SWF

You can find a full list of services here.

Why can’t I find the command for my service?

AWS has this to say:

Some services have a separate CLI from before a single AWS CLI was created that works with all services. These service-specific CLIs have separate documentation that is linked from the service’s documentation page. Documentation for service-specific CLIs does not apply to the AWS CLI.

Where can I find an API reference?

Sometimes you just want to read the documentation. We can’t blame you! Experimenting and using the help flag is great, but when you need all the details, there’s no substitute for reading the docs. You can find a set of API reference documentation on the AWS documentation website.

What all does the API reference contain?

The content of an API reference varies based on how the services’ API is constructed and which protocol is used. Typically, a services’ API reference will contain detailed information on actions (subcommands), data sent to and from the service, and possible error conditions.

NOTE: The AWS CLI Reference provides the content of all AWS CLI commands’ help files.

Can I load parameters from a file instead of always typing them?

Of course! You should always try to work smarter and not harder. Several of the Amazon Web Service commands support two commands to aid you in generating a parameter skeleton and loading the parameters from a file, respectively --generate-cli-skeleton and --cli-input-json. The first generates a JSON file containing all the available parameters for the specified command. The second will load settings from that file when you use the command.

You can find more information on loading parameters from a file here.

Where can I find even more information?

Even more information about the AWS CLI can be found in the User Guide under using the AWS CLI and working with services.

Success! And Congratulations!

You finally made it! Through this series of guides, you’ve learned how to install, configure, and interact with AWS through the command line interface. This guide completes the series and we hope you’ve learned enough to feel confident using the AWS CLI to manage your infrastructure.

Have questions? Are you using a cool CLI feature that you think everyone should know about? Let us know in the comments!

You might also like
Leave A Reply

Your email address will not be published.