AWS ElasticSearchのドメインをAWS CLIで作成してみた (ドラフト版)


http://aws.typepad.com/aws_japan/2015/10/amazon-elasticsearch-service.html を参考にAWS CLIでESドメインを作成してみました。

とりあえずの動作確認だけなので、期間限定公開です。
(ちゃんとハンズオンを作成したら消します。)


ドメインの作成
==============

ドメイン名の指定
----------------

```bash:変数の設定:
ES_DOMAIN_NAME='my-es-cluster'
```


インスタンスタイプの指定
------------------------

```bash:変数の設定:
ES_INSTANCE_TYPE='t2.micro.elasticsearch'
```


インスタンス数の指定
--------------------

```bash:変数の設定:
ES_INSTANCE_COUNT='1'
```


dedicated masterの設定値
------------------------

```bash:変数の設定:
ES_DEDICATED_MASTER_ENABLED='false'
```


zone awarenessの設定値
----------------------

```bash:変数の設定:
ES_ZONE_AWARENESS_ENABLED='false'
```


設定値の集約
------------

```bash:変数の設定:
ES_CLUSTER_CONFIG="InstanceType=${ES_INSTANCE_TYPE},InstanceCount=${ES_INSTANCE_COUNT},DedicatedMasterEnabled=${ES_DEDICATED_MASTER_ENABLED},ZoneAwarenessEnabled=${ES_ZONE_AWARENESS_ENABLED}" \
        && echo "${ES_CLUSTER_CONFIG}"
```


EBSの設定
-----------

```bash:変数の設定:
EBS_ENABLED='true'
EBS_TYPE='gp2'
EBS_SIZE='10'
```

```bash:変数の設定:
ES_EBS_OPTIONS="EBSEnabled=${EBS_ENABLED},VolumeType=${EBS_TYPE},VolumeSize=${EBS_SIZE}" \
        && echo ${ES_EBS_OPTIONS}
```


アクセスポリシーの設定値
------------------------

(省略)


ドメインの作成
--------------

```bash:コマンド:
aws es create-elasticsearch-domain \
        --domain-name ${ES_DOMAIN_NAME} \
        --elasticsearch-cluster-config ${ES_CLUSTER_CONFIG} \
        --ebs-options ${ES_EBS_OPTIONS}
```

```bash:変数の確認:
cat << ETX

  ES_DOMAIN_NAME:    ${ES_DOMAIN_NAME}
  ES_CLUSTER_CONFIG: ${ES_CLUSTER_CONFIG}
  ES_EBS_OPTIONS:    ${ES_EBS_OPTIONS}

ETX
```

```json:結果(例)
      {
        "DomainStatus": {
            "ElasticsearchClusterConfig": {
                "DedicatedMasterEnabled": false,
                "InstanceCount": 1,
                "ZoneAwarenessEnabled": false,
                "InstanceType": "t2.micro.elasticsearch"
            },
            "DomainId": "XXXXXXXXXXXX/my-es-cluster",
            "Created": true,
            "Deleted": false,
            "EBSOptions": {
                "VolumeSize": 10,
                "VolumeType": "gp2",
                "EBSEnabled": true
            },
            "Processing": true,
            "DomainName": "my-es-cluster",
            "SnapshotOptions": {
                "AutomatedSnapshotStartHour": 0
            },
            "AccessPolicies": "",
            "AdvancedOptions": {
                "rest.action.multi.allow_explicit_index": "true"
            },
            "ARN": "arn:aws:es:us-west-2:XXXXXXXXXXXX:domain/my-es-cluster"
        }
      }
```


ドメインの確認
----------

```bash:コマンド:
aws es describe-elasticsearch-domain \
        --domain-name ${ES_DOMAIN_NAME}
```

```json:結果(例)

      {
        "DomainStatus": {
            "ElasticsearchClusterConfig": {
                "DedicatedMasterEnabled": false,
                "InstanceCount": 1,
                "ZoneAwarenessEnabled": false,
                "InstanceType": "t2.micro.elasticsearch"
            },
            "DomainId": "XXXXXXXXXXXX/my-es-cluster",
            "Created": true,
            "Deleted": false,
            "EBSOptions": {
                "VolumeSize": 10,
                "VolumeType": "gp2",
                "EBSEnabled": true
            },
            "Processing": true,
            "DomainName": "my-es-cluster",
            "SnapshotOptions": {
                "AutomatedSnapshotStartHour": 0
            },
            "AccessPolicies": "",
            "AdvancedOptions": {
                "rest.action.multi.allow_explicit_index": "true"
            },
            "ARN": "arn:aws:es:us-west-2:XXXXXXXXXXXX:domain/my-es-cluster"
        }
      }
```

設定の確認
----------

```bash:コマンド:
aws es describe-elasticsearch-domain-config \
        --domain-name ${ES_DOMAIN_NAME}
```

```json:結果(例)

      {
        "DomainConfig": {
            "ElasticsearchClusterConfig": {
                "Status": {
                    "PendingDeletion": false,
                    "State": "Processing",
                    "CreationDate": 1444168220.598,
                    "UpdateVersion": 2,
                    "UpdateDate": 1444168220.598
                },
                "Options": {
                    "DedicatedMasterEnabled": false,
                    "InstanceCount": 1,
                    "ZoneAwarenessEnabled": false,
                    "InstanceType": "t2.micro.elasticsearch"
                }
            },
            "AdvancedOptions": {
                "Status": {
                    "PendingDeletion": false,
                    "State": "Active",
                    "CreationDate": 1444168326.565,
                    "UpdateVersion": 4,
                    "UpdateDate": 1444168326.565
                },
                "Options": {
                    "rest.action.multi.allow_explicit_index": "true"
                }
            },
            "EBSOptions": {
                "Status": {
                    "PendingDeletion": false,
                    "State": "Processing",
                    "CreationDate": 1444168220.598,
                    "UpdateVersion": 2,
                    "UpdateDate": 1444168220.598
                },
                "Options": {
                    "VolumeSize": 10,
                    "VolumeType": "gp2",
                    "EBSEnabled": true
                }
            },
            "AccessPolicies": {
                "Status": {
                    "PendingDeletion": false,
                    "State": "Active",
                    "CreationDate": 1444168326.565,
                    "UpdateVersion": 4,
                    "UpdateDate": 1444168326.565
                },
                "Options": ""
            },
            "SnapshotOptions": {
                "Status": {
                    "PendingDeletion": false,
                    "State": "Processing",
                    "CreationDate": 1444168220.598,
                    "UpdateVersion": 2,
                    "UpdateDate": 1444168220.598
                },
                "Options": {
                    "AutomatedSnapshotStartHour": 0
                }
            }
        }
      }
```






完了
------