![Page 1: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/1.jpg)
aws cli
Deep dive into the awscommand line interface
John Varghese – Devops Architect at YuzuMay 20, 2015
![Page 2: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/2.jpg)
Pro Tip
• When starting a presentation
– Turn off notifications– Quit iMessages– Quit your IM– Quit Outlook
![Page 3: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/3.jpg)
Who is using it today?
• Please raise you hand
![Page 4: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/4.jpg)
What is aws-cli?
• A unified tool • It provides a consistent interface for
interacting with all parts of AWS
![Page 5: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/5.jpg)
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
![Page 6: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/6.jpg)
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
![Page 7: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/7.jpg)
Command structure
aws [options] <command> <subcommand> [parameters]
![Page 8: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/8.jpg)
Some aws commands
• cloudformation• configure• ec2• elb• rds• route53
• cloudwatch• dynamodb• elasticache• redshift• s3api• And all the rest…
![Page 9: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/9.jpg)
Got oh-my-zsh?
Add the plugin (awscli)I just added it yesterday after all this
time. It is awesome!
![Page 10: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/10.jpg)
Auto-complete
Both bash and zsh have auto-complete for aws cli
![Page 11: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/11.jpg)
When you run into issues
Use the option --debug
![Page 12: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/12.jpg)
aws configure
~/.aws/config~/.aws/credentials
![Page 13: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/13.jpg)
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
Use these Environment Variables to override the configuration settings.
There are a half dozen such variables.
![Page 14: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/14.jpg)
Output formats
• Json• Text• Table
• --output • Demo command– aws cloudformation list-
stack-resources --stack-name yuzu-es-dev-stack
![Page 15: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/15.jpg)
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
![Page 16: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/16.jpg)
--dry-runJust validate the command
Also --no-dry-run Default behaviour
![Page 17: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/17.jpg)
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
![Page 18: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/18.jpg)
JMESpath
• A short diversion• Visit JMESpath.org
• Iteration• [0]• [*]• []• ?
• Demo – python syntax– Try out some of the
examples on the tutorial
![Page 19: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/19.jpg)
--query
Use this to filter the results.
Demo commands on following slides
![Page 20: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/20.jpg)
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}'
![Page 21: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/21.jpg)
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}’
![Page 22: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/22.jpg)
Filtering multiple elements
• Use the list notation: [key1, key2]
• aws ec2 describe-volumes --query 'Volumes[*].[VolumeId, Attachments[0].InstanceId, AvailabilityZone, Size]'
![Page 23: Deep Dive into AWS CLI - the command line interface](https://reader034.vdocument.in/reader034/viewer/2022050805/55ce6c49bb61ebac7e8b469f/html5/thumbnails/23.jpg)
Filter by value of a field
• Use the JMESPath "?" operator
• Note the backticks
• aws ec2 describe-volumes --query 'Volumes[?AvailabilityZone==`us-east-1d`]'