KEMBAR78
Deep Dive into AWS CLI - the command line interface | PPTX
aws cli
Deep dive into the aws
command line interface
John Varghese – Devops Architect at Yuzu
May 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_ID
AWS_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-run
Just 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:Attachm
ents[0].InstanceId,AZ:AvailabilityZone,Size:Siz
e}’
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`]'

Deep Dive into AWS CLI - the command line interface

  • 1.
    aws cli Deep diveinto the aws command line interface John Varghese – Devops Architect at Yuzu May 20, 2015
  • 2.
    Pro Tip • Whenstarting a presentation – Turn off notifications – Quit iMessages – Quit your IM – Quit Outlook
  • 3.
    Who is usingit today? • Please raise you hand
  • 4.
    What is aws-cli? •A unified tool • It provides a consistent interface for interacting with all parts of AWS
  • 5.
    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
  • 6.
    aws help • Showsyou the basic meta parameters that are independent of the actual service/command, or sub command. • These meta parameters are also called options
  • 7.
    Command structure aws [options]<command> <subcommand> [parameters]
  • 8.
    Some aws commands •cloudformation • configure • ec2 • elb • rds • route53 • cloudwatch • dynamodb • elasticache • redshift • s3api • And all the rest…
  • 9.
    Got oh-my-zsh? Add theplugin (awscli) I just added it yesterday after all this time. It is awesome!
  • 10.
    Auto-complete Both bash andzsh have auto- complete for aws cli
  • 11.
    When you runinto issues Use the option --debug
  • 12.
  • 13.
    AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY Use these EnvironmentVariables to override the configuration settings. There are a half dozen such variables.
  • 14.
    Output formats • Json •Text • Table • --output • Demo command – aws cloudformation list- stack-resources --stack- name yuzu-es-dev-stack
  • 15.
    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
  • 16.
    --dry-run Just validate thecommand Also --no-dry-run Default behaviour
  • 17.
    describe-regions with --dry-run awsec2 describe-regions --generate-cli- skeleton > x.json aws ec2 describe-regions --cli-input-json file://x.json A contrived example
  • 18.
    JMESpath • A shortdiversion • Visit JMESpath.org • Iteration • [0] • [*] • [] • ? • Demo – python syntax – Try out some of the examples on the tutorial
  • 19.
    --query Use this tofilter the results. Demo commands on following slides
  • 20.
    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}'
  • 21.
    Filtering results somemore • Chained keys such as key1.key2[0].key3 • Attachments[0].InstanceId • aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,InstanceId:Attachm ents[0].InstanceId,AZ:AvailabilityZone,Size:Siz e}’
  • 22.
    Filtering multiple elements •Use the list notation: [key1, key2] • aws ec2 describe-volumes --query 'Volumes[*].[VolumeId, Attachments[0].InstanceId, AvailabilityZone, Size]'
  • 23.
    Filter by valueof a field • Use the JMESPath "?" operator • Note the backticks • aws ec2 describe-volumes --query 'Volumes[?AvailabilityZone==`us-east-1d`]'