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
