首页 > 解决方案 > 用于预置 Elastic Search 的 AWS Cloud Formation 模板

问题描述

我想通过cloudformation模板配置一个ES域。

我有一个服务将使用这个 ES 域,所以每当该服务部署到 ECS 时,我想首先创建一个 ES 域并在我的服务中使用 ES 端点。

这个模板有帮助吗?

另外,我将如何通过模板设置在 SSM 中新创建的 ES 端点?

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "taskRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "",
              "Effect": "Allow",
              "Principal": {
                "Service": "ecs-tasks.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
            }
          ]
        },
        "Path": "/",
        "Policies": [
          {
            "PolicyName": "taskRole",
            "PolicyDocument": {
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": [
                    "ssm:GetParametersByPath",
                    "ssm:GetParameter"
                  ],
                  "Resource": "arn:aws:ssm:*:*:parameter/*"
                }
              ]
            }
          }
        ]

      }
    },
    "ElasticsearchDomain": {
      "Type": "AWS::Elasticsearch::Domain",
      "Properties": {
        "DomainName": "Test-ES-Domain",
        "ElasticsearchClusterConfig": {
          "DedicatedMasterEnabled": "true",
          "InstanceCount": "2",
          "ZoneAwarenessEnabled": "true",
          "InstanceType": "m3.medium.elasticsearch",
          "DedicatedMasterType": "m3.medium.elasticsearch",
          "DedicatedMasterCount": "3"
        },
        "EBSOptions": {
          "EBSEnabled": true,
          "Iops": 0,
          "VolumeSize": 20,
          "VolumeType": "gp2"
        },
        "SnapshotOptions": {
          "AutomatedSnapshotStartHour": "0"
        },
        "AccessPolicies": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "AWS": "arn:aws:iam::123456789012:user/es-user"
              },
              "Action": "es:*",
              "Resource": "arn:aws:es:us-east-1:123456789012:domain/test/*"
            }
          ]
        },
        "AdvancedOptions": {
          "rest.action.multi.allow_explicit_index": "true"
        }
      }
    }
  },
  "Outputs": {
    "serviceRole": {
      "Description": "Task role with permission to read configurations from AWS parameter store",
      "Value": { "Fn::GetAtt": [ "taskRole", "Arn" ] }
    }
  }
}

标签: elasticsearchamazon-cloudformation

解决方案


这是我的 ES CloudFormation 模板:https ://github.com/Talderon/AWS_CloudFormation/tree/master/ElasticSearch

随意通过然后将它们分开。

对于您要问的 SSM 部分,我将不得不对此进行一些研究。:P


推荐阅读