introduction of aws-cli

17
AWS Command Line Interface (aws-cli)をつかってみた #awspad 2013-02-18 ひろせ まさあき

Upload: masaaki-hirose

Post on 10-May-2015

3.805 views

Category:

Technology


0 download

DESCRIPTION

Introduction of aws-cli

TRANSCRIPT

Page 1: Introduction of aws-cli

AWS Command Line Interface (aws-cli)をつかってみた

#awspad2013-02-18

ひろせ まさあき

Page 2: Introduction of aws-cli

自己紹介• ひろせ まさあき @hirose31

• インフラエンジニア :D

• 『サーバ/インフラを支える技術』, 2008

• 最近の関心事• NATインスタンスの冗長化 (single subnet, multiAZ)

• タダでELBを暖機する方法• サブネットとかVPCに名前つけたいですぅ

Page 3: Introduction of aws-cli

aws-cli?

Page 4: Introduction of aws-cli

aws-cli

• 2012-12公開

• 最新 0.5.3 (Developer Preview)

• http://aws.amazon.com/cli/

• https://github.com/aws/aws-cli

• http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html

Page 5: Introduction of aws-cli

aws-cli VS

EC2 API tool

• 1コマンドで複数サービスに対応

• Python (not Java)

• 結果がJSON (textも可)

• bash, zshの補完可能

Page 6: Introduction of aws-cli

AWS::CLIWrapperPerl module, wrapping aws-cli

use  AWS::CLIWrapper;  my  $aws  = AWS::CLIWrapper->new;  my  $res  = $aws->ec2('describe-instances', {    instance_ids  => ['i-XXXXX', 'i-YYYYY'],   });  

Page 7: Introduction of aws-cli

使い方 / 環境設定$ export AWS_ACCESS_KEY_ID=<access_key>

$ export AWS_SECRET_ACCESS_KEY=<secret_key>

$ export AWS_DEFAULT_REGION=us-west-2

or

$ export AWS_CONFIG_FILE=/path/to/config_file

Page 8: Introduction of aws-cli

使い方 / help

$ aws help

$ aws ec2 help

$ aws ec2 describe-instances help

Page 9: Introduction of aws-cli

使い方 / 引数• string

• そのまま文字列

• list• --instance-ids 'i-AAA' 'i-BBB' (space separaed)

× 'i-AAA i-BBB' (NOT quoted as single string)

× 'i-AAA, i-BBB' (NOT comma separated)

× '["i-AAA", "i-BBB"]' (NOT JSON)

• structure• JSON

• list + structure = space separated + JSON• --filters '{"name":"tag:Name","values": ["web*","db*"]}' '{"name"...}'

Page 10: Introduction of aws-cli

使い方 / 補完

bash

$ complete -C aws_completer aws

zsh

$ source bin/zsh_complete.sh

Page 11: Introduction of aws-cli

使い方 / jq• jq

• lightweight and flexible command-line JSON processor

• http://stedolan.github.com/jq/

$ aws ec2 describe-instances | \ jq '.reservationSet[].instancesSet[] | {instanceId, instanceType}'{ "instanceType": "m2.2xlarge", "instanceId": "i-AAA"}{ "instanceType": "c1.xlarge", "instanceId": "i-BBB"}...

Page 12: Introduction of aws-cli

おはまり• AWS_DEFAULT_REGIONが効かない!!

• 0.5.0で修正

• https://github.com/aws/aws-cli/pull/36

Page 13: Introduction of aws-cli

おはまり• ec2 create-tagsが動かない!!

• 0.5.0で修正

• https://github.com/aws/aws-cli/issues/33

Page 14: Introduction of aws-cli

おはまりかも?と思ったらaws --debug SERVICE COMMAND ...

で、API リファレンスとにらめっこ

$ aws --debug ec2 describe-instances --filters '{"name":"tag:Name","values": ["web*","db*"]}'...AWSAccessKeyId=XXX&Action=DescribeInstances&Filter.1.Name=tag%3AName&Filter.1.Value.1=web%2A&Filter.1.Value.2=db%2A&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2013-02-17T15%3A47%3A36.787450&Version=2012-12-01...

Page 15: Introduction of aws-cli

今後• 対応サービスの追加

EC2 VPC ELBAuto ScalingSQS SNS SES

Elastic Beanstalk CloudFormationIAM

S3 RDS Route 53CloudFront ElastiCache SimpleDB

CloudWatch...

Page 16: Introduction of aws-cli

今後• あれ?おかしいな?と思ったら…

• https://github.com/aws/aws-cli

• issue

• pull request

Page 17: Introduction of aws-cli

Thanks :D