Table of Contents

AWS CLI

Universal Command Line Interface for Amazon Web Services



Refalence


Install

Linux, Mac

# easy_install pip
# pip install awscli
# aws --version
# yum install jq

Windows

Download and Install

http://aws.amazon.com/cli/?nc2=h_ls


Configuration

Configuration of Access Key ID & Secret Access Key

# aws configure

AWS Access Key ID [None]: youraccesskey  
AWS Secret Access Key [None]: yoursecretkey  
Default region name [None]: ap-northeast-1     # Tokyo
Default output format [None]: json  

# aws configure –profile other-account

$ cat ~/.aws/config
[default]
output = json
region = ap-northeast-1

$ cat ~/.aws/credentials 
[default]
aws_access_key_id = xxxxxxxxxx
aws_secret_access_key = xxxxxxxxxx

tmp environment

$ export AWS_ACCESS_KEY_ID=xxxxxxxxxx
$ export AWS_SECRET_ACCESS_KEY=xxxxxxxxxx
$ export AWS_DEFAULT_REGION=ap-northeast-1
$ export AWS_DEFAULT_OUTPUT=json

$ aws ec2 describe-instances

other environment

aws configure --profile tmpaws


fill the gap in bash

$ sudo yum install aws-cli-zsh
$ echo 'complete -C aws_completer aws' >>~/.bash_profile
$ source ~/.bash_profile


Operation

EC2

http://docs.aws.amazon.com/cli/latest/reference/ec2/index.html

Description Command
help ec2 option aws ec2 help
List Instance aws ec2 describe-instances
aws ec2 describe-instances --output json
aws ec2 describe-instances --output text
aws ec2 describe-instances --output table
Start Instance aws ec2 start-instances --instance-ids i-AAAA
Stop Instance aws ec2 stop-instances --instance-ids i-AAAAA
Terminate Instance aws ec2 terminate-instances --instance-ids i-AAAA
List a AMI aws ec2 describe-images
List my AMI aws ec2 describe-images --owners self

S3

http://docs.aws.amazon.com/cli/latest/reference/s3/index.html

Description Command
help s3 option aws s3 help
list bucket aws s3 ls
make bucket (mb) aws s3 mb s3://tmpbucket
aws s3 mb s3://mybucket --region us-west-1
remove bucket (rb) aws s3 rb s3://tmpbucket
aws s3 rb s3://tmpbucket --force ← If there is a object in the bucket, you must use “–force” option.
list s3 aws s3 ls s3://tmpbucket/box/
copy to s3 aws s3 cp a.txt s3://tmpbucket
copy to s3 with recursive aws s3 cp TESTDIR s3://tmpbucket/box --recursive
copy to s3 with read permission aws s3 cp a.txt s3://tmpbucket --acl public-read
copy from s3 aws s3 cp s3://tmpbucket/a.txt a.txt
copy from s3 with recursive aws s3 cp s3://tmpbucket/dir dir --recursive
delete a file aws s3 rm s3://tmpbucket/a.txt
delete directory aws s3 rm s3://tmpbucket/box --recursive
rsync aws s3 sync localsync s3://tmpbucket/synctest/
rsync aws s3 sync s3://tmpbucket/synctest/ localsync
rsync aws s3 sync localsync s3://tmpbucket/synctest/ --delete
rsync aws s3 sync localsync s3://tmpbucket/synctest/ --exclude "ignore/*"

ELB

http://docs.aws.amazon.com/cli/latest/reference/elb/index.html

Description Command
help elb option aws elb help
Check ELB aws elb describe-instance-health --load-balancer-name ELBTEST
Register instance to LB aws elb register-instances-with-load-balancer --load-balancer-name LBTEST --instances i-AAAAA
Deregister instance from LB aws elb deregister-instances-from-load-balancer --load-balancer-name LBTEST --instances i-AAAAA