Deep Dive into AWS CLI - the command line interface

Post on 15-Aug-2015

62 views 0 download

transcript

aws cli

Deep dive into the awscommand line interface

John Varghese – Devops Architect at YuzuMay 20, 2015

Pro Tip

• When starting a presentation

– Turn off notifications– Quit iMessages– Quit your IM– Quit Outlook

Who is using it today?

• Please raise you hand

What is aws-cli?

• A unified tool • It provides a consistent interface for

interacting with all parts of AWS

Installation

• Without brew (on *nix)– Install python 2.x.– Python 3.x will not work– wget, unzip, execute awscli-bundle.zip

• With homebrew– brew install awscli

aws help

• Shows you the basic meta parameters that are independent of the actual service/command, or sub command.

• These meta parameters are also called options

Command structure

aws [options] <command> <subcommand> [parameters]

Some aws commands

• cloudformation• configure• ec2• elb• rds• route53

• cloudwatch• dynamodb• elasticache• redshift• s3api• And all the rest…

Got oh-my-zsh?

Add the plugin (awscli)I just added it yesterday after all this

time. It is awesome!

Auto-complete

Both bash and zsh have auto-complete for aws cli

When you run into issues

Use the option --debug

aws configure

~/.aws/config~/.aws/credentials

AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY

Use these Environment Variables to override the configuration settings.

There are a half dozen such variables.

Output formats

• Json• Text• Table

• --output • Demo command– aws cloudformation list-

stack-resources --stack-name yuzu-es-dev-stack

Parameters via json

• aws cloudformation list-stack-resources --stack-name yuzu-es-dev-stack --generate-cli-skeleton

• aws cloudformation list-stack-resources --cli-input-json file://x.json

--dry-runJust validate the command

Also --no-dry-run Default behaviour

describe-regions with --dry-run

aws ec2 describe-regions --generate-cli-skeleton > x.json

aws ec2 describe-regions --cli-input-json file://x.json

A contrived example

JMESpath

• A short diversion• Visit JMESpath.org

• Iteration• [0]• [*]• []• ?

• Demo – python syntax– Try out some of the

examples on the tutorial

--query

Use this to filter the results.

Demo commands on following slides

Filtering the results

• aws ec2 describe-volumes– Leverage head -10

• aws ec2 describe-volumes --query 'Volumes[0]’

• aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,AZ:AvailabilityZone,Size:Size}'

Filtering results some more

• Chained keys such as key1.key2[0].key3

• Attachments[0].InstanceId

• aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,InstanceId:Attachments[0].InstanceId,AZ:AvailabilityZone,Size:Size}’

Filtering multiple elements

• Use the list notation: [key1, key2]

• aws ec2 describe-volumes --query 'Volumes[*].[VolumeId, Attachments[0].InstanceId, AvailabilityZone, Size]'

Filter by value of a field

• Use the JMESPath "?" operator

• Note the backticks

• aws ec2 describe-volumes --query 'Volumes[?AvailabilityZone==`us-east-1d`]'