Skip to content

Instantly share code, notes, and snippets.

@KondaTomoyuki
Created November 12, 2014 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KondaTomoyuki/19ca8e282895814b277e to your computer and use it in GitHub Desktop.
Save KondaTomoyuki/19ca8e282895814b277e to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Launch single instances.",
"Parameters": {
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "String",
"MinLength": "1",
"MaxLength": "255",
"Default": "sample-key",
"AllowedPattern": "[\\x20-\\x7E]*",
"ConstraintDescription": "can contain only ASCII characters."
},
"ImageId": {
"Description": "The AMI name that will use in Web/AP Server",
"Type": "String",
"Default": "ami-c50864ff",
"ConstraintDescription": "must be a valid AMI name of the form ami-xxxxxxxx."
},
"InstanceType": {
"Description": "Web/AP Server EC2 instance type",
"Type": "String",
"Default": "m3.medium",
"AllowedValues": ["m1.medium", "m3.medium"],
"ConstraintDescription": "must be a valid EC2 instance type."
},
"SSHLocation": {
"Description": "The IP address range that can be used to SSH to the EC2 instances",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
},
"Subnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": { "Ref": "VPC" },
"CidrBlock": "10.0.1.0/24"
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway"
},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": { "Ref": "VPC" },
"InternetGatewayId": { "Ref": "InternetGateway" }
}
},
"Route": {
"Type": "AWS::EC2::Route",
"Properties": {
"DestinationCidrBlock": "0.0.0.0/0",
"RouteTableId": { "Ref": "RouteTable" },
"GatewayId": { "Ref": "InternetGateway" }
}
},
"RouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": { "Ref": "VPC" }
}
},
"SubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": { "Ref": "Subnet" },
"RouteTableId": { "Ref": "RouteTable" }
}
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": { "Ref": "VPC" },
"GroupDescription": "Enable SSH access via port 22",
"SecurityGroupIngress": [
{ "IpProtocol": "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": { "Ref": "SSHLocation" } },
{ "IpProtocol": "tcp", "FromPort": "80", "ToPort": "80", "CidrIp": "0.0.0.0/0" }
]
}
},
"IPAddress": {
"Type": "AWS::EC2::EIP",
"DependsOn": ["AttachGateway", "SubnetRouteTableAssociation"],
"Properties": {
"Domain": "vpc",
"InstanceId": { "Ref": "ServerInstance" }
}
},
"ServerInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"Comment": "Launch instance from AMI",
"AWS::CloudFormation::Init": {
"config": {}
}
},
"Properties": {
"ImageId": { "Ref": "ImageId" },
"NetworkInterfaces": [{
"DeviceIndex": "0",
"AssociatePublicIpAddress": true,
"DeleteOnTermination": true,
"Description": "test description",
"PrivateIpAddress": "10.0.1.10",
"GroupSet": [{ "Ref": "SecurityGroup" }],
"SubnetId": { "Ref": "Subnet" }
}],
"InstanceType": { "Ref": "InstanceType" },
"KeyName": { "Ref": "KeyName" },
"Tags": [{ "Key": "Name", "Value": "Web/AP Instance" }],
"UserData": { "Fn::Base64": { "Fn::Join": ["", [
"#!/bin/bash\n",
"# Helper function\n",
"function error_exit\n",
"{\n",
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref": "ServerWaitHandle" }, "'\n",
" exit 1\n",
"}\n",
"# All done so signal success\n",
"/opt/aws/bin/cfn-signal -e 0 -r \"Web/AP Server setup complete\" '", { "Ref": "ServerWaitHandle" }, "'\n"
]]}}
}
},
"ServerWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle"
},
"ServerWaitCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": ["ServerInstance"],
"Properties": {
"Count": "1",
"Handle": { "Ref": "ServerWaitHandle" },
"Timeout": "3000"
}
}
},
"Outputs": {
"EIP": {
"Value": { "Ref": "IPAddress" },
"Description": "Published URL on Web/AP server for Aipo."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment