Skip to content

Instantly share code, notes, and snippets.

@solarce
Created June 5, 2013 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solarce/5716564 to your computer and use it in GitHub Desktop.
Save solarce/5716564 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "make an instance, based on region, subnet, and security group. Uses AMI Mapping for Instance Store backed Amazon Linux 64bit in the region specified",
"Parameters" : {
"InstanceType" : {
"Description" : "Type of Instance to use, defaults to m1.medium",
"Type" : "String",
"Default" : "m1.medium"
},
"KeyName" : {
"Description" : "Name of and existing EC2 KeyPair to enable SSH access to the instance",
"Type" : "String"
},
"VpcId" : {
"Type" : "String",
"Description" : "VpcId of your existing Virtual Private Cloud (VPC)"
},
"SubnetId" : {
"Type" : "String",
"Description" : "SubnetId of an existing subnet in your Virtual Private Cloud (VPC)"
},
"SecurityGroupId" : {
"Type" : "String",
"Description" : "SecurityGroup to use"
},
"ServerName" : {
"Type" : "String",
"Description" : "FQDN of the server"
},
"IpAddress" : {
"Type" : "String",
"Description" : "The IP of the server, should match DNS"
}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : { "AMI" : "ami-e8249881" },
"us-west-1" : { "AMI" : "ami-21f9de64" },
"us-west-2" : { "AMI" : "ami-2e31bf1e" },
"eu-west-1" : { "AMI" : "ami-b57474c1" },
"sa-east-1" : { "AMI" : "ami-1608d10b" },
"ap-southeast-1" : { "AMI" : "ami-a8a7e7fa" },
"ap-northeast-1" : { "AMI" : "ami-5a6cd35b" }
}
},
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : {
"Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ] },
"SecurityGroupIds" : [{ "Ref" : "SecurityGroupId" }],
"SubnetId" : { "Ref" : "SubnetId" },
"PrivateIpAddress" : { "Ref" : "IpAddress"},
"InstanceType" : { "Ref" : "InstanceType"},
"Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ServerName"} } ],
"UserData" : { "Fn::Base64" :
{ "Fn::Join" : ["",
[
"#!/bin/bash -v\n",
"perl -i -pe 's/disable_root: 1/disable_root: 0/' /etc/cloud/cloud.cfg\n",
"perl -i -pe 's/#PermitRootLogin .*/PermitRootLogin without-password/' /etc/ssh/sshd_config\n",
"cp /home/ec2-user/.ssh/authorized_keys /root/.ssh/authorized_keys\n",
"/etc/init.d/sshd reload\n",
{ "Fn::Join" : [ "", [ "sed -i 's/localhost.localdomain/", { "Ref" : "ServerName"}, "/g' /etc/sysconfig/network", "\n" ]]},
{ "Fn::Join" : [ "", [ "hostname ", { "Ref" : "ServerName"}, "\n" ]]},
"yum install redhat-lsb-core -y\n",
"yum update -y\n"
]
]
}
},
"KeyName" : { "Ref" : "KeyName" }
}
}
},
"Outputs" : {
"InstanceId" : {
"Value" : { "Ref" : "EC2Instance" },
"Description" : "Instance Id of newly created instance"
},
"InstanceIP": {
"Value" : { "Fn::GetAtt" : [ "EC2Instance" , "PrivateIp" ] },
"Description" : "Private IP for instance"
},
"Subnet" : {
"Value" : { "Ref" : "SubnetId" },
"Description" : "Subnet of instance"
},
"SecurityGroupId" : {
"Value" : { "Ref" : "SecurityGroupId" },
"Description" : "Security Group of instance"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment