0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

0.5から始めるAWS CLI入門 - ②基本使用

Last updated at Posted at 2016-02-20

AWS CLI勉強中の内容をまとめていきます。
PREV:0.5から始めるAWS CLI入門 - ①AWS CLIのインストールと基本設定


#記法

$ aws <サービス> <コマンド> <オプション> <引数>

#コマンド
キーペアを参照してみる

$ aws ec2 describe-key-pairs
{
    "KeyPairs": [
        {
            "KeyName": "Main-key", 
            "KeyFingerprint": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
        },  
        {
            "KeyName": "Sub-key", 
            "KeyFingerprint": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
        }
    ]
}

#オプション
なんせ膨大ですし、実際に利用する時はAWS CLI Command Referenceを参照したほうがいいですね。

よく使いそうなfiltersとqueryだけ
##--filters
条件指定検索

$ aws ec2 describe-key-pairs --filters "Name=key-name,Values=Main-key"
{
    "KeyPairs": [
        {
            "KeyName": "Main-key", 
            "KeyFingerprint": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
        }
    ]
}

Nameで指定するとこが若干違いますね
KeyName→key-name
やっぱりAWS CLI Command Referenceを参照したほうがいい
##--query
出力結果絞り込み

$ aws ec2 describe-key-pairs --query 'KeyPairs[].KeyName'
[
    "Main-key", 
    "Sub-key"
]

queryの場合は項目を階層的に指定する
###複数項目出力

$ aws ec2 describe-key-pairs --query 'KeyPairs[].[KeyName,KeyFingerprint]'
[
    [
        "Main-key",
        "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
    ], 
    [
        "Sub-key", 
        "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
    ]
]

###条件指定

$ aws ec2 describe-key-pairs --query 'KeyPairs[?KeyName==`Main-key`]'
[
    {
        "KeyName": "Main-key", 
        "KeyFingerprint": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
    }
]

###別名を付ける

$ aws ec2 describe-key-pairs --query 'KeyPairs[?KeyName==`Main-key`].{KN:KeyName,KF:KeyFingerprint}'
[
    {
        "KN": "Main-key", 
        "KF": "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:gg:hh:ii:jj"
    }
]

「<」「<=」「==」「>=」「>」「!=」などの演算子も利用できるので複雑ですね。


間違い、改善点などありましたらご指摘お願いします。

Next:0.5から始めるAWS CLI入門 - ③VPCの構築

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?