Skip to content

Instantly share code, notes, and snippets.

@mirajavora
Last active April 4, 2021 15:20
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mirajavora/65db44bf44507e74f6fe to your computer and use it in GitHub Desktop.
Save mirajavora/65db44bf44507e74f6fe to your computer and use it in GitHub Desktop.
Elastic Search AWS Cloudformation Script
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Creates auto scaling Elastic Search Cluster",
"Parameters" : {
"InstanceType" : {
"Description" : "Elastic Search node instance type",
"Type" : "String",
"Default" : "t2.small",
"AllowedValues" : [ "t1.micro", "t2.micro", "t2.small", "t2.medium", "m1.small", "m1.medium", "m1.large",
"m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge",
"c3.4xlarge", "c3.8xlarge", "g2.2xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge",
"hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"InstanceCount" : {
"Description" : "Number of instances to start",
"Default": "3",
"MinValue": "2",
"MaxValue": "12",
"Type" : "Number"
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription" : "Must be the name of an existing EC2 KeyPair."
},
"VPCId" : {
"Description" : "VPC you are trying launch the instances in",
"Type" : "AWS::EC2::VPC::Id",
"ConstraintDescription" : "Must be a valid vpc ID"
},
"SubnetIds" : {
"Description" : "Specify subnets where to launch the instances",
"Type" : "List<AWS::EC2::Subnet::Id>",
"ConstraintDescription" : "Must be a subnet"
},
"SubnetAZ": {
"Description": "Availability Zones of the Subnet",
"Type": "List<AWS::EC2::AvailabilityZone::Name>"
},
"Environment": {
"AllowedValues": [
"local",
"dev",
"staging",
"prod"
],
"ConstraintDescription": "must be a valid environment",
"Default": "dev",
"Description": "Environment",
"Type": "String"
},
"ServiceName": {
"Default": "",
"Description": "Service Name",
"Type": "String"
}
},
"Mappings" : {
"AWSInstanceType2Arch": {
"t1.micro": {"Arch": "PV64"},
"t2.micro": {"Arch": "HVM64"},
"t2.small": {"Arch": "HVM64"},
"t2.medium": {"Arch": "HVM64"},
"m1.small": {"Arch": "PV64"},
"m1.medium": {"Arch": "PV64"},
"m1.large": {"Arch": "PV64"},
"m1.xlarge": {"Arch": "PV64"},
"m2.xlarge": {"Arch": "PV64"},
"m2.2xlarge": {"Arch": "PV64"},
"m2.4xlarge": {"Arch": "PV64"},
"m3.medium": {"Arch": "HVM64"},
"m3.large": {"Arch": "HVM64"},
"m3.xlarge": {"Arch": "HVM64"},
"m3.2xlarge": {"Arch": "HVM64"},
"c1.medium": {"Arch": "PV64"},
"c1.xlarge": {"Arch": "PV64"},
"c3.large": {"Arch": "HVM64"},
"c3.xlarge": {"Arch": "HVM64"},
"c3.2xlarge": {"Arch": "HVM64"},
"c3.4xlarge": {"Arch": "HVM64"},
"c3.8xlarge": {"Arch": "HVM64"},
"g2.2xlarge": {"Arch": "HVMG2"},
"r3.large": {"Arch": "HVM64"},
"r3.xlarge": {"Arch": "HVM64"},
"r3.2xlarge": {"Arch": "HVM64"},
"r3.4xlarge": {"Arch": "HVM64"},
"r3.8xlarge": {"Arch": "HVM64"},
"i2.xlarge": {"Arch": "HVM64"},
"i2.2xlarge": {"Arch": "HVM64"},
"i2.4xlarge": {"Arch": "HVM64"},
"i2.8xlarge": {"Arch": "HVM64"},
"hi1.4xlarge": {"Arch": "HVM64"},
"hs1.8xlarge": {"Arch": "HVM64"},
"cr1.8xlarge": {"Arch": "HVM64"},
"cc2.8xlarge": {"Arch": "HVM64"}
},
"AWSRegionArch2AMI": {
"us-east-1": {
"HVM64": "ami-21630d44"
},
"us-west-2": {
"HVM64": "ami-cf3c21ff"
},
"us-west-1": {
"HVM64": "ami-c52dd781"
},
"eu-west-1": {
"HVM64": "ami-9d2f0fea"
},
"ap-southeast-1": {
"HVM64": "ami-96c2c8c4"
},
"ap-northeast-1": {
"HVM64": "ami-0841ca08"
},
"ap-southeast-2": {
"HVM64": "ami-f32b64c9"
},
"sa-east-1": {
"HVM64": "ami-4ddb4e50"
},
"cn-north-1": {
"HVM64": "ami-18980421"
},
"eu-central-1": {
"HVM64": "ami-6265657f"
}
}
},
"Resources" : {
"RootRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Principal": {
"Service": [ "ec2.amazonaws.com" ]
},
"Action": [ "sts:AssumeRole" ]
} ]
},
"Path": "/",
"Policies": [
{
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect":"Allow",
"Action":"iam:PassRole",
"Resource":"*"
},
{
"Effect":"Allow",
"Action":"iam:ListInstanceProfiles",
"Resource":"*"
},
{
"Effect":"Allow",
"Action":"ec2:*",
"Resource":"*"
}]
},
"PolicyName": "allowEC2"
}
]
}
},
"ElasticSearchProfile": {
"Properties": {
"Path": "/",
"Roles": [
{
"Ref": "RootRole"
}
]
},
"Type": "AWS::IAM::InstanceProfile"
},
"ElasticSearchSecurityGroup": {
"Metadata" : { "Note" : "Replace with your own IP address/range" },
"Properties": {
"GroupDescription": "Security group allows access to ES from specific IP range",
"SecurityGroupIngress": [
{
"CidrIp": "0.0.0.0/0",
"FromPort": "22",
"IpProtocol": "tcp",
"ToPort": "22"
},
{
"CidrIp": "0.0.0.0/0",
"FromPort": "9200",
"IpProtocol": "tcp",
"ToPort": "9200"
},
{
"CidrIp": "0.0.0.0/0",
"FromPort": "9300",
"IpProtocol": "tcp",
"ToPort": "9300"
}
],
"VpcId": { "Ref": "VPCId"}
},
"Type": "AWS::EC2::SecurityGroup"
},
"ServerGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": { "Ref" : "SubnetAZ" },
"VPCZoneIdentifier" : { "Ref": "SubnetIds"},
"LaunchConfigurationName": {
"Ref": "ESLaunchConfig"
},
"MinSize": "2",
"MaxSize": "12",
"DesiredCapacity": {
"Ref": "InstanceCount"
},
"Tags": [
{ "Key": "Name", "Value": { "Ref": "AWS::StackName" }, "PropagateAtLaunch": true },
{ "Key": "Environment", "Value": { "Ref": "Environment" }, "PropagateAtLaunch": true },
{ "Key": "Owner", "Value": "Owner", "PropagateAtLaunch": true },
{ "Key": "Service", "Value": { "Ref": "ServiceName" }, "PropagateAtLaunch": true }
]
}
},
"ESLaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"InstanceType": {"Ref": "InstanceType"},
"IamInstanceProfile": {
"Ref": "ElasticSearchProfile"
},
"SecurityGroups": [
{ "Ref": "ElasticSearchSecurityGroup" }
],
"KeyName": {"Ref": "KeyName"},
"ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"VolumeSize": "100",
"VolumeType" : "gp2"
}
}
]
}
}
},
"Outputs" : {
}
}
@deepamaknikar
Copy link

How do I launch Elastic Search 2.3 domain suing this template? Where do I specify the version for ES?

@prats84
Copy link

prats84 commented Nov 9, 2016

You would need to bake your own AMI with 2.3 and reference it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment