AWS commands in a nutshell

AWS CLI is an common CLI tool for managing the AWS resources. With this single tool we can manage all the aws resources.

sudo apt-get install -y python-dev python-pip 
sudo pip install awscli
aws --version
aws configure

Bash one-liners

cat # output a file
tee # split output into a file
cut -f 2 # print the 2nd column, per line
sed -n ‘5{p;q}’ # print the 5th line in a file
sed 1d # print all lines, except the first
tail -n +2 # print all lines, starting on the 2nd
head -n 5 # print the first 5 lines
tail -n 5 # print the last 5 lines

expand # convert tabs to 4 spaces
unexpand -a # convert 4 spaces to tabs
wc # word count
tr ‘ ‘ \t # translate / convert characters to other characters

sort # sort data
uniq # show only unique entries
paste # combine rows of text, by line
join # combine rows of text, by initial column value

Cloudtrail – Logging and Auditing

list all trails
aws cloudtrail describe-trails
list all S3 buckets
aws s3 ls
create a new trail
aws cloudtrail create-subscription \
--name awslog \
--s3-new-bucket awslog2016
list the names of all trails
aws cloudtrail describe-trails --output text | cut -f 8
get the status of a trail
aws cloudtrail get-trail-status \
--name awslog
delete a trail
aws cloudtrail delete-trail \
--name awslog
delete the S3 bucket of a trail
aws s3 rb s3://awslog2016 --force
add tags to a trail, up to 10 tags
aws cloudtrail add-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"
list the tags of a trail
aws cloudtrail list-tags \
--resource-id-list
remove a tag from a trail
aws cloudtrail remove-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"

Posted in AWS

Leave a Reply

Your email address will not be published. Required fields are marked *