
先日AWS Command Line Interfaceなるものが発表されました。Python向けコマンドラインインターフェースとのことですが、別にたいした発表でも…と思ったのですが面白そうなので試してみました。
自分の場合はMacにPythonがセットアップ済みなので、あとの導入は簡単です。
$ sudo easy_install pip $ sudo pip install awscli
あとは.bash_profileに設定ファイルパスの環境変数追加。
AWS_CONFIG_FILE=/path/to/awscli.conf export AWS_CONFIG_FILE
加えて設定ファイル設置。
$ cat /path/to/awscli.conf [default] aws_access_key_id=<Access Key Id> aws_secret_access_key=<Secret Access Key> region=ap-northeast-1
これでコマンドが実行できるようになります。
$ aws help aws The AWS Command Line Interface is a unified tool that provides a consistent interface for interacting with all parts of AWS. aws [options] service operation [parameters] Use 'aws service help' for information on a specific service. Available services: * iam * ses * rds * elb * autoscaling * cloudwatch * sqs * cloudformation * elasticbeanstalk * sns * sts * directconnect * emr * ec2 Options --output <output_format> * json * text --region <region_name> * us-east-1 * ap-northeast-1 * sa-east-1 * ap-southeast-1 * ap-southeast-2 * us-west-2 * us-west-1 * eu-west-1 --version Display the version of this tool --debug Turn on debug logging --profile <profile_name> Use a specific profile from your credential file --endpoint-url <endpoint_url> Override service's default URL with the given URL
bashユーザーにはウレシイ仕掛けがあります。
$ complete -C aws_completer aws $ aws [TAB] autoscaling directconnect elb rds sqs cloudformation ec2 emr ses sts cloudwatch elasticbeanstalk iam sns $ aws
そうです。complete -C aws_completer awsとするとサブコマンドのオートコンプリートが効くのです!なんかイイ感じ♫
ところでコマンドの出力結果はJSONみたいですねぇ。簡易的な変更管理に使えそうなのでやってみました。セキュリティグループの設定を一部削除した前後を保存して、gitでバージョン管理してみる例です。
$ aws ec2 describe-security-groups > security-groups.json
$ git add security-groups.json
$ git commit -m "First version"
[master 26376c0] First version
1 file changed, 721 insertions(+)
create mode 100644 security-groups.json
$ git push
Username for 'https://github.com': kazgoto
Password for 'https://kazgoto@github.com':
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.81 KiB, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/kazgoto/awscli-test.git
1c15bed..26376c0 master -> master
$ aws ec2 describe-security-groups > security-groups.json
$ git diff
diff --git a/security-groups.json b/security-groups.json
index b625310..3674ffe 100644
--- a/security-groups.json
+++ b/security-groups.json
@@ -64,6 +64,17 @@
],
"groups": [],
"fromPort": 80
+ },
+ {
+ "toPort": 8080,
+ "ipProtocol": "tcp",
+ "ipRanges": [
+ {
+ "cidrIp": "0.0.0.0/0"
+ }
+ ],
+ "groups": [],
+ "fromPort": 8080
}
],
"groupName": "default",
@@ -717,5 +728,5 @@
"groupDescription": "op-ec2"
}
],
- "requestId": "05b37412-4c1b-443c-aa0e-e8e1c405dfe8"
+ "requestId": "104a76f5-3134-4da1-8b2b-5185b1d565f2"
}
$ git commit -a -m "Second version"
[master 04730be] Second version
1 file changed, 12 insertions(+), 1 deletion(-)
$ git push
Username for 'https://github.com': kazgoto
Password for 'https://kazgoto@github.com':
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 404 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/kazgoto/awscli-test.git
26376c0..04730be master -> master
githubでみるとこんな状態で変更点が見やすい。

githubでみるほどでもないですが、何か重要な変更を行うときにパッと見で確認できるのがいいなぁと、思いました。