Amazon Web Services
This guide covers setting up and using the AWS Command Line Interface (CLI) for interacting with various AWS services.
AWS CLI Installation
For fresh Ubuntu instances:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip && sudo ./aws/install && rm -rf ./awscliv2.zip ./aws
For other operating systems, refer to the official installation guide.
Shell Completion Setup
Set up shell completion for the AWS CLI so you can use tab to autocomplete commands and options.
Bash
Add to your ~/.bashrc
:
complete -C '/usr/local/bin/aws_completer' aws
Zsh
Add to your ~/.zshrc
:
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '/usr/local/bin/aws_completer' aws
Important
If you installed the AWS CLI in a different location, update the path
accordingly. For example, if you installed it using homebrew, the path
might be /opt/homebrew/bin/aws_completer
.
AWS CLI Configuration
Set up your AWS credentials:
aws configure
You'll be prompted for:
- AWS Access Key ID
- AWS Secret Access Key
- Default region name (e.g., us-east-1)
- Default output format (json, text, or table)
Tip
You can set up multiple profiles using aws configure --profile profilename
Basic AWS CLI Usage
List S3 Buckets
aws s3 ls
List EC2 Instances
aws ec2 describe-instances
Create an IAM User
aws iam create-user --user-name newuser
Advanced CLI Features
Using JSON Parameters
For complex API calls, you can use JSON files:
aws ec2 run-instances --cli-input-json file://ec2-params.json
JMESPath Querying
Use --query
to filter output:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name]'
AWS CLI Aliases
Create shortcuts for common commands in ~/.aws/cli/alias
:
[toplevel]
todays-instances = ec2 describe-instances --query 'Reservations[].Instances[?LaunchTime>=`2023-01-01`]'
Use with: aws todays-instances
References
- AWS CLI Command Reference
- S3 CLI Reference
- EC2 CLI Reference
- IAM CLI Reference
- Glacier CLI Reference
Page last updated on 2024-10-17.