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
で、ぐぐったら↓ にたどり着きました。
というか、書こうとしてたこと全部書いてあるじゃんね。
ちゃんちゃん。