Getting started with AWS CLI

Getting started with AWS CLI

AWS has extremely nice UI. But – with the time, you need to do something faster than just clicking via an interface. Sometimes you need to automate something (start/stop instances, make a backup. If you are wondering – there is a perfect time for CLI.

Let’s start with setting up out configuration data:

aws configure --profile client

Why –profile ? Because sooner or later we get to the point we have to manage multiple accounts. It’s easier to set this up per client. Now we can use it in a regular way:

aws ec2 describe-instances --profile client

And now we can use command line, couple useful examples:

To run backup of your instance (create an AMi image) just type:


m=$( date +"%Y-%m" )
b1=$(/usr/local/bin/aws ec2 create-image --profile client --instance-id=i-0000000 --name "$m-name" --description "$m backup")

To start/stop multiple instaces EC2/RDS i’m using something like that:


case $1 in
	aws ec2 stop-instances --profile client --region ap-southeast-2 --instance-ids i-xxxx i-yyyy
	aws rds stop-db-instance --profile client --region ap-southeast-2 --db-instance-identifier mysql01a-aws-syd
	aws ec2 start-instances --profile client --region ap-southeast-2 --instance-ids i-xxxx i-yyyy
	aws rds start-db-instance --profile client --region ap-southeast-2 --db-instance-identifier mysql01a-aws-syd

echo "Use with start / stop parameter"