liveBook · Manning

AWS CLI

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

AWS Command Line Interface is a tool for managing AWS services by entering commands in a terminal.

The AWS Command Line Interface (AWS CLI) lets you manage AWS services from a terminal. It runs on Linux, macOS, and Windows. Commands can be saved in scripts, making repeated tasks easier to reproduce and share. section 4.2 section 4.1.1

To get started:

  • Install the CLI for your operating system, then run `aws --version` to verify it. The installation guidance calls for version 2.4.0 or later. section 4.2.1
  • Enter a service and an action: `aws <service> <action> [--name value ...]`. For example, `aws ec2 describe-instances --filters "Name=instance-type,Values=t2.micro"` lists matching instances. Use `aws help`, `aws <service> help`, or `aws <service> <action> help` when you need command details. section 4.2.3
  • Expect JSON output unless you select another format. Use `--query` with JMESPath to extract a field, and `--output text` when a script needs the value without JSON string quotes. section 4.2.4

Automate a virtual machine

A Bash or PowerShell script can look up an Amazon Machine Image (AMI), a default VPC, and a subnet; launch a t2.micro EC2 instance; wait for it; and terminate it when finished. Capturing IDs with `--query` and `--output text` lets later commands reuse them. This example handles only one virtual machine, so it is not a general-purpose deployment system. section 4.2.4

Back up files to S3

Create a bucket with `aws s3 mb s3://awsinaction-$yourname`, replacing `$yourname` with a value that makes the bucket name unique. Then run `aws s3 sync $path s3://awsinaction-$yourname/backup` to upload new or changed files. To restore them, use `aws s3 cp --recursive s3://awsinaction-$yourname/backup $path`. Start with a small folder: storage is pay-per-use, and a large upload can take time or exceed the Free Tier. section 7.3

For automation, use Bash on Linux or macOS and PowerShell on Windows. Be cautious with the Windows installation guidance: setting PowerShell's execution policy to `Unrestricted` permits unsigned scripts and carries a malicious-script risk. section 4.2.4 section 4.2.1

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Works through installation, command syntax, output queries, and scripts, while noting that the virtual-machine script handles only one instance.
Examples
Shows a filtered EC2 instance listing, virtual-machine lifecycle scripts, and S3 backup and restore commands.
What it assumes
Introduces installation and service/action syntax from the beginning; assumes an AWS account for inspecting its instances.
What you can do after
Operate/configure it to inspect EC2 instances, script a single virtual machine's lifecycle, and back up files to S3.
How it connects
Connects EC2, AMIs, VPCs, subnets, JMESPath, Bash, and PowerShell in a virtual-machine workflow.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.