LoginSignup
37
29

More than 5 years have passed since last update.

aws cli の generate-cli-skeleton オプションが便利!

Last updated at Posted at 2014-11-27

aws コマンドパラメータを json形式で手で書くのしんどいですが、
--generate-cli-skeleton というオプションつけて実行すると、
パラメータのひな形を生成してくれます。

例)

$ aws dynamodb create-table --generate-cli-skeleton

{
    "AttributeDefinitions": [
        {
            "AttributeName": "",
            "AttributeType": ""
        }
    ],
    "TableName": "",
    "KeySchema": [
        {
            "AttributeName": "",
            "KeyType": ""
        }
    ],
    "LocalSecondaryIndexes": [
        {
            "IndexName": "",
            "KeySchema": [
                {
                    "AttributeName": "",
                    "KeyType": ""
                }
            ],
            "Projection": {
                "ProjectionType": "",
                "NonKeyAttributes": [
                    ""
                ]
            }
        }
    ],
    "GlobalSecondaryIndexes": [
        {
            "IndexName": "",
            "KeySchema": [
                {
                    "AttributeName": "",
                    "KeyType": ""
                }
            ],
            "Projection": {
                "ProjectionType": "",
                "NonKeyAttributes": [
                    ""
                ]
            },
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 0,
                "WriteCapacityUnits": 0
            }
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 0,
        "WriteCapacityUnits": 0
    }
}

こいつをファイルとかに書き出して、編集し、それを--cli-input-json で食わせるとよい。

$ aws dynamodb create-table --generate-cli-skeleton > table.json

$ vi table.json

{
    "AttributeDefinitions": [
        {
            "AttributeName": "user_id",
            "AttributeType": "S"
        },
        {
            "AttributeName": "timestamp",
            "AttributeType": "N"
        }
    ],
    "TableName": "user_log",
    "KeySchema": [
        {
            "AttributeName": "user_id",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "timestamp",
            "KeyType": "RANGE"
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    }
}
$ aws dynamodb create-table --cli-input-json file://table.json \
--endpoint-url http://localhost:8000

この file:// というのを 付けないと、下記のようなイミフなエラーが出てしまいます。
JSONが正しくないのか、何度も見なおしてしまったよ…

Error parsing parameter 'cli-input-json': Invalid JSON: No JSON object could be decoded
JSON received: skel.json

で、ぐぐったら↓ にたどり着きました。

というか、書こうとしてたこと全部書いてあるじゃんね。

ちゃんちゃん。

37
29
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
37
29